, before that there's left bar navigation
32 |
33 | cat "$html" | sed -e 's/^\s\+//' | awk '
34 | /^
/ { doit=1; next; }
35 | /^<\/body>/ { doit=0; next; }
36 | doit==1 { print; }'
37 |
38 | cat << EOF
39 |
40 |
41 | EOF
42 |
--------------------------------------------------------------------------------
/tests/cli-tests/006-qgroup-show-sync/test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # simple test of qgroup show --sync option
4 |
5 | source "$TEST_TOP/common" || exit
6 |
7 | check_prereq mkfs.btrfs
8 | check_prereq btrfs
9 |
10 | setup_root_helper
11 | prepare_test_dev 1g
12 |
13 | run_check_mkfs_test_dev
14 | run_check_mount_test_dev
15 |
16 | run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/Sub"
17 | run_check $SUDO_HELPER "$TOP/btrfs" quota enable "$TEST_MNT/Sub"
18 |
19 | for opt in '' '--' '--sync'; do
20 | run_check $SUDO_HELPER "$TOP/btrfs" qgroup limit 300M "$TEST_MNT/Sub"
21 | run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/Sub/file" bs=1M count=200
22 |
23 | run_check $SUDO_HELPER "$TOP/btrfs" qgroup show -re $opt "$TEST_MNT/Sub"
24 |
25 | run_check $SUDO_HELPER "$TOP/btrfs" qgroup limit none "$TEST_MNT/Sub"
26 | run_check $SUDO_HELPER rm -f "$TEST_MNT/Sub/file"
27 | run_check "$TOP/btrfs" filesystem sync "$TEST_MNT/Sub"
28 | done
29 |
30 | run_check_umount_test_dev
31 |
--------------------------------------------------------------------------------
/tests/cli-tests/007-check-force/test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # test 'btrfs check --force' on a mounted filesystem
4 |
5 | source "$TEST_TOP/common" || exit
6 |
7 | check_prereq mkfs.btrfs
8 | check_prereq btrfs
9 |
10 | setup_root_helper
11 |
12 | # we need to use a real block device, because the check opens the device in
13 | # exclusive mode, that unfortunately behaves differently for direct file
14 | # access and for the real /dev/loop0 device
15 | setup_loopdevs 1
16 | prepare_loopdevs
17 | TEST_DEV=${loopdevs[1]}
18 |
19 | run_check_mkfs_test_dev
20 | run_check_mount_test_dev
21 | run_mustfail "checking mounted filesystem without --force" \
22 | $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV"
23 | run_check $SUDO_HELPER "$TOP/btrfs" check --force "$TEST_DEV"
24 | run_check $SUDO_HELPER "$TOP/btrfs" check --force --repair "$TEST_DEV"
25 | run_check_umount_test_dev
26 | run_check $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV"
27 | run_check $SUDO_HELPER "$TOP/btrfs" check --force "$TEST_DEV"
28 |
29 | cleanup_loopdevs
30 |
--------------------------------------------------------------------------------
/tests/convert-tests/017-fs-near-full/test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Check if btrfs-convert creates filesystem with device extents beyond the
3 | # device boundary
4 |
5 | source "$TEST_TOP/common" || exit
6 | source "$TEST_TOP/common.convert" || exit
7 |
8 | check_prereq btrfs-convert
9 | check_global_prereq mke2fs
10 | check_global_prereq fallocate
11 |
12 | setup_root_helper
13 | prepare_test_dev 1G
14 |
15 | convert_test_prep_fs ext4 mke2fs -t ext4 -b 4096
16 |
17 | # Use up 800MiB first
18 | for i in $(seq 1 4); do
19 | run_check $SUDO_HELPER fallocate -l 200M "$TEST_MNT/file$i"
20 | done
21 |
22 | # Then add 5MiB for above files. These 5 MiB will be allocated near the very
23 | # end of the fs, to confuse btrfs-convert
24 | for i in $(seq 1 4); do
25 | run_check $SUDO_HELPER fallocate -l 205M "$TEST_MNT/file$i"
26 | done
27 |
28 | run_check_umount_test_dev
29 |
30 | # convert_test_do_convert() will call btrfs check, which should expose any
31 | # invalid inline extent with too large size
32 | convert_test_do_convert
33 |
--------------------------------------------------------------------------------
/ci/actions/delete-all-runs-of-branch:
--------------------------------------------------------------------------------
1 | #!/bin/sh -e
2 |
3 | type -p gh > /dev/null || { echo "ERROR: gh tool not found"; exit 1; }
4 | type -p jq > /dev/null || { echo "ERROR: jq tool not found"; exit 1; }
5 |
6 | repo="kdave/btrfs-progs"
7 | branch="$1"
8 |
9 | if [ -z "$branch" ]; then
10 | echo "ERROR: $0 branch"
11 | exit 1
12 | fi
13 |
14 | notthatone() {
15 | echo "ERROR: protected branch, will not remove: $1"
16 | exit 1
17 | }
18 |
19 | areyousure() {
20 | echo "WARNING: protected branch, make sure you want to remove it: $1"
21 | }
22 |
23 | case "$branch" in
24 | master) notthatone "$branch";;
25 | devel) areyousure "$branch";;
26 | esac
27 |
28 | echo "Delete all runs of branch $branch, are you sure? [y/N]"
29 | read -n 1 answer
30 | if ! [ "$answer" = 'y' ]; then
31 | echo "INFO: not deleting"
32 | exit 0
33 | fi
34 | echo
35 |
36 | for id in $(gh run -R "$repo" list --limit 100 --json databaseId --branch "$branch" | jq '.[].databaseId'); do
37 | echo "Delete run $id"
38 | gh run -R "$repo" delete "$id"
39 | done
40 |
--------------------------------------------------------------------------------
/tests/misc-tests/026-image-non-printable-chars/test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # check that sanitized names with matching crc do not contain unprintable
3 | # characters, namely 0x7f
4 |
5 | source "$TEST_TOP/common" || exit
6 |
7 | check_prereq mkfs.btrfs
8 | check_prereq btrfs
9 |
10 | setup_root_helper
11 | prepare_test_dev
12 |
13 | run_check_mkfs_test_dev
14 | run_check_mount_test_dev
15 | run_check $SUDO_HELPER chmod a+rw "$TEST_MNT"
16 |
17 | # known to produce char 0x7f == 127
18 | touch "$TEST_MNT/|5gp!"
19 |
20 | run_check_umount_test_dev
21 |
22 | _mktemp_local img
23 | _mktemp_local img.restored
24 | _mktemp_local img.dump
25 | run_check $SUDO_HELPER "$TOP/btrfs-image" -ss "$TEST_DEV" img
26 | run_check $SUDO_HELPER "$TOP/btrfs-image" -r img img.restored
27 | run_check_stdout $SUDO_HELPER "$TOP/btrfs" inspect-internal dump-tree img.restored > img.dump
28 |
29 | ch7f=$(echo -en '\x7f')
30 | if grep -q "$ch7f" img.dump; then
31 | _fail "found char 0x7f in the sanitized names"
32 | fi
33 |
34 | rm -f -- img img.restored img.dump
35 |
--------------------------------------------------------------------------------
/common/tree-search.h:
--------------------------------------------------------------------------------
1 | #ifndef __COMMON_TREE_SEARCH_H__
2 | #define __COMMON_TREE_SEARCH_H__
3 |
4 | #include "kerncompat.h"
5 | #include
6 | #include "kernel-shared/uapi/btrfs.h"
7 |
8 | #define BTRFS_TREE_SEARCH_V2_BUF_SIZE 65536
9 |
10 | struct btrfs_tree_search_args {
11 | bool use_v2;
12 | union {
13 | struct btrfs_ioctl_search_args args1;
14 | struct btrfs_ioctl_search_args_v2 args2;
15 | u8 filler[sizeof(struct btrfs_ioctl_search_args_v2) +
16 | BTRFS_TREE_SEARCH_V2_BUF_SIZE];
17 | };
18 | };
19 |
20 | int btrfs_tree_search_ioctl(int fd, struct btrfs_tree_search_args *sa);
21 |
22 | static inline struct btrfs_ioctl_search_key *btrfs_tree_search_sk(struct btrfs_tree_search_args *sa)
23 | {
24 | /* Same offset for v1 and v2. */
25 | return &sa->args1.key;
26 | }
27 |
28 | static inline void *btrfs_tree_search_data(struct btrfs_tree_search_args *sa, unsigned long offset) {
29 | if (sa->use_v2)
30 | return (void *)(sa->args2.buf + offset);
31 | return (void *)(sa->args1.buf + offset);
32 | }
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/ci/ci-build-almalinux10:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Usage: $0 [branch] [configure options]
3 | # Create source tarball from HEAD or given branch and build it in AlmaLinux 10 CI
4 | # environment. Configure options follow branch name that can be empty.
5 |
6 | HERE=`pwd`
7 | if [ -f "configure.ac" ]; then
8 | SOURCEDIR=`pwd`
9 | elif [ -f "../configure.ac" ]; then
10 | cd ..
11 | SOURCEDIR=`pwd`
12 | else
13 | echo "ERROR: cannot determine source directory from `pwd`"
14 | exit 1
15 | fi
16 |
17 | CIIMAGEDIR=ci/images/ci-almalinux-10-x86_64
18 | BRANCH=${1:-HEAD}
19 | if [ "$#" -ge 1 ]; then
20 | shift
21 | fi
22 | HASH=$(git log -1 --format='%h %s' "$BRANCH")
23 |
24 | echo "CI: Generate archive from $BRANCH ($HASH)"
25 | git archive --prefix=btrfs-progs-devel/ -o devel.tar "$BRANCH"
26 | echo "$BRANCH $HASH" > GITCOMMIT
27 | tar uvf devel.tar GITCOMMIT
28 | #rm GITCOMMIT
29 | gzip --force --best devel.tar
30 |
31 | cd "$CIIMAGEDIR"
32 | cp "$SOURCEDIR/devel.tar.gz" .
33 | ./docker-build
34 | ./docker-run -- ./test-build devel --disable-documentation "$@"
35 |
--------------------------------------------------------------------------------
/ci/ci-build-rockylinux9:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Usage: $0 [branch] [configure options]
3 | # Create source tarball from HEAD or given branch and build it in RockyLinux 9 CI
4 | # environment. Configure options follow branch name that can be empty.
5 |
6 | HERE=`pwd`
7 | if [ -f "configure.ac" ]; then
8 | SOURCEDIR=`pwd`
9 | elif [ -f "../configure.ac" ]; then
10 | cd ..
11 | SOURCEDIR=`pwd`
12 | else
13 | echo "ERROR: cannot determine source directory from `pwd`"
14 | exit 1
15 | fi
16 |
17 | CIIMAGEDIR=ci/images/ci-rockylinux-9-x86_64
18 | BRANCH=${1:-HEAD}
19 | if [ "$#" -ge 1 ]; then
20 | shift
21 | fi
22 | HASH=$(git log -1 --format='%h %s' "$BRANCH")
23 |
24 | echo "CI: Generate archive from $BRANCH ($HASH)"
25 | git archive --prefix=btrfs-progs-devel/ -o devel.tar "$BRANCH"
26 | echo "$BRANCH $HASH" > GITCOMMIT
27 | tar uvf devel.tar GITCOMMIT
28 | #rm GITCOMMIT
29 | gzip --force --best devel.tar
30 |
31 | cd "$CIIMAGEDIR"
32 | cp "$SOURCEDIR/devel.tar.gz" .
33 | ./docker-build
34 | ./docker-run -- ./test-build devel --disable-documentation "$@"
35 |
--------------------------------------------------------------------------------
/tests/fsck-tests/031-metadatadump-check-data-csum/test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # To check if "btrfs check" can detect metadata dump (restored by btrfs-image)
3 | # and ignore --check-data-csum option
4 |
5 | source "$TEST_TOP/common" || exit
6 |
7 | check_prereq btrfs
8 | check_prereq mkfs.btrfs
9 | check_prereq btrfs-image
10 | setup_root_helper
11 | prepare_test_dev
12 |
13 | run_check_mkfs_test_dev
14 | run_check_mount_test_dev
15 |
16 | run_check $SUDO_HELPER dd if=/dev/urandom of="$TEST_MNT/file" bs=4k count=16
17 | run_check_umount_test_dev
18 |
19 | _mktemp_local restored_image
20 | run_check $SUDO_HELPER "$TOP/btrfs-image" "$TEST_DEV" "restored_image"
21 |
22 | # use prepare_test_dev() to wipe all existing data on $TEST_DEV
23 | # so there is no way that restored image could have matching data csum
24 | prepare_test_dev
25 |
26 | run_check $SUDO_HELPER "$TOP/btrfs-image" -r "restored_image" "$TEST_DEV"
27 |
28 | # Should not report any error
29 | run_check "$TOP/btrfs" check --check-data-csum "$TEST_DEV"
30 |
31 | rm -rf -- "restored_image"
32 |
--------------------------------------------------------------------------------
/tests/misc-tests/015-dump-super-garbage/test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # let dump-super dump random data, must not crash
4 |
5 | source "$TEST_TOP/common" || exit
6 |
7 | check_prereq btrfs
8 |
9 | run_mustfail "attempt to print bad superblock without force" \
10 | "$TOP/btrfs" inspect-internal dump-super /dev/urandom
11 | run_mustfail "attempt to print bad superblock without force" \
12 | "$TOP/btrfs" inspect-internal dump-super -a /dev/urandom
13 | run_mustfail "attempt to print bad superblock without force" \
14 | "$TOP/btrfs" inspect-internal dump-super -fa /dev/urandom
15 |
16 | # All forced, no failure
17 | run_check "$TOP/btrfs" inspect-internal dump-super -Ffa /dev/urandom
18 | run_check "$TOP/btrfs" inspect-internal dump-super -Ffa /dev/urandom
19 | run_check "$TOP/btrfs" inspect-internal dump-super -Ffa /dev/urandom
20 | run_check "$TOP/btrfs" inspect-internal dump-super -Ffa /dev/urandom
21 | run_check "$TOP/btrfs" inspect-internal dump-super -Ffa /dev/urandom
22 | run_check "$TOP/btrfs" inspect-internal dump-super -Ffa /dev/urandom
23 |
--------------------------------------------------------------------------------
/tests/misc-tests/031-qgroup-parent-child-relation/test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Test that btrfs 'qgroup show' outputs the correct parent-child qgroup relation
3 |
4 | source "$TEST_TOP/common" || exit
5 |
6 | check_prereq mkfs.btrfs
7 | check_prereq btrfs
8 |
9 | setup_root_helper
10 | prepare_test_dev
11 |
12 | run_check_mkfs_test_dev
13 | run_check_mount_test_dev
14 |
15 | run_check $SUDO_HELPER "$TOP/btrfs" quota enable "$TEST_MNT"
16 | run_check $SUDO_HELPER "$TOP/btrfs" qgroup create 1/0 "$TEST_MNT"
17 | run_check $SUDO_HELPER "$TOP/btrfs" qgroup assign 0/5 1/0 "$TEST_MNT"
18 | run_check $SUDO_HELPER "$TOP/btrfs" quota rescan -w "$TEST_MNT"
19 |
20 | run_check_stdout $SUDO_HELPER "$TOP/btrfs" qgroup show --sort=-qgroupid \
21 | -p "$TEST_MNT" | grep -q "1/0" \
22 | || _fail "parent qgroup check failed, please check the log"
23 | run_check_stdout $SUDO_HELPER "$TOP/btrfs" qgroup show --sort=qgroupid \
24 | -c "$TEST_MNT" | grep -q "0/5" \
25 | || _fail "child qgroup check failed, please check the log"
26 |
27 | run_check_umount_test_dev "$TEST_MNT"
28 |
--------------------------------------------------------------------------------
/tests/mkfs-tests/012-rootdir-no-shrink/test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Test if mkfs.btrfs --rootdir will skip shrinking correctly
3 |
4 | source "$TEST_TOP/common" || exit
5 |
6 | check_prereq mkfs.btrfs
7 |
8 | setup_root_helper
9 |
10 | fs_size=$((512 * 1024 * 1024))
11 | bs=$((1024 * 1024))
12 | tmp=$(_mktemp_dir mkfs-rootdir)
13 |
14 | prepare_test_dev "$fs_size"
15 |
16 | # No shrink case
17 |
18 | run_check_mkfs_test_dev --rootdir "$tmp"
19 | run_check_mount_test_dev
20 |
21 | # We should be able to write at least half of the fs size data since the fs is
22 | # not shrunk
23 | run_check $SUDO_HELPER dd if=/dev/zero bs="$bs" count=$(($fs_size / $bs / 2)) \
24 | of="$TEST_MNT/file"
25 |
26 | run_check_umount_test_dev
27 |
28 | # Shrink case
29 |
30 | run_check_mkfs_test_dev --rootdir "$tmp" --shrink
31 | run_check_mount_test_dev
32 |
33 | run_mustfail "mkfs.btrfs for shrink rootdir" \
34 | $SUDO_HELPER dd if=/dev/zero bs="$bs" count=$(($fs_size / $bs / 2)) \
35 | of="$TEST_MNT/file"
36 |
37 | run_check_umount_test_dev
38 |
39 | rm -rf -- "$tmp"
40 |
--------------------------------------------------------------------------------
/ci/ci-build-musl:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Usage: $0 [branch] [configure options]
3 | # Create source tarball from HEAD or given branch and build it in musl CI
4 | # environment. Configure options follow branch name that can be empty.
5 |
6 | HERE=`pwd`
7 | if [ -f "configure.ac" ]; then
8 | SOURCEDIR=`pwd`
9 | elif [ -f "../configure.ac" ]; then
10 | cd ..
11 | SOURCEDIR=`pwd`
12 | else
13 | echo "ERROR: cannot determine source directory from `pwd`"
14 | exit 1
15 | fi
16 |
17 | CIIMAGEDIR=ci/images/ci-musl-x86_64
18 | BRANCH=${1:-HEAD}
19 | if [ "$#" -ge 1 ]; then
20 | shift
21 | fi
22 | HASH=$(git log -1 --format='%h %s' "$BRANCH")
23 |
24 | echo "CI: Generate archive from $BRANCH ($HASH)"
25 | git archive --prefix=btrfs-progs-devel/ -o devel.tar "$BRANCH"
26 | echo "$BRANCH $HASH" > GITCOMMIT
27 | tar uvf devel.tar GITCOMMIT
28 | #rm GITCOMMIT
29 | gzip --force --best devel.tar
30 |
31 | cd "$CIIMAGEDIR"
32 | cp "$SOURCEDIR/devel.tar.gz" .
33 | ./docker-build
34 | ./docker-run -- ./test-build devel --disable-documentation --disable-backtrace --disable-libudev "$@"
35 |
--------------------------------------------------------------------------------
/ci/ci-build-tumbleweed:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Usage: $0 [branch] [configure options]
3 | # Create source tarball from HEAD or given branch and build it in openSUSE Tumbleweed CI
4 | # environment. Configure options follow branch name that can be empty.
5 |
6 | HERE=`pwd`
7 | if [ -f "configure.ac" ]; then
8 | SOURCEDIR=`pwd`
9 | elif [ -f "../configure.ac" ]; then
10 | cd ..
11 | SOURCEDIR=`pwd`
12 | else
13 | echo "ERROR: cannot determine source directory from `pwd`"
14 | exit 1
15 | fi
16 |
17 | CIIMAGEDIR=ci/images/ci-openSUSE-tumbleweed-x86_64
18 | BRANCH=${1:-HEAD}
19 | if [ "$#" -ge 1 ]; then
20 | shift
21 | fi
22 | HASH=$(git log -1 --format='%h %s' "$BRANCH")
23 |
24 | echo "CI: Generate archive from $BRANCH ($HASH)"
25 | git archive --prefix=btrfs-progs-devel/ -o devel.tar "$BRANCH"
26 | echo "$BRANCH $HASH" > GITCOMMIT
27 | tar uvf devel.tar GITCOMMIT
28 | #rm GITCOMMIT
29 | gzip --force --best devel.tar
30 |
31 | cd "$CIIMAGEDIR"
32 | cp "$SOURCEDIR/devel.tar.gz" .
33 | ./docker-build
34 | ./docker-run -- ./test-build devel --disable-documentation "$@"
35 |
--------------------------------------------------------------------------------
/tests/common.local:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # additional arguments to various commands
4 |
5 | # already defined, eg. via make argument
6 | if [ -z "$TEST_ENABLE_OVERRIDE" ]; then
7 | # set to 'true'
8 | TEST_ENABLE_OVERRIDE=false
9 |
10 | TEST_ARGS_CHECK=--mode=lowmem
11 | fi
12 |
13 |
14 | # gets arguments of a current command and can decide if the argument insertion
15 | # should happen, eg. if some option combination does not make sense or would
16 | # break tests
17 | #
18 | # Return 0 if we need to skip option override
19 | # Return 1 if we don't need to skip option override
20 | _skip_spec()
21 | {
22 | local beacon
23 |
24 | beacon=.lowmem_repairable
25 |
26 | # For lowmem repair, only support fs tree repair for now
27 | # So we place lowmem repair beacon in the same dir of the test case
28 | if echo "$TEST_ARGS_CHECK" | grep -q 'mode=lowmem' &&
29 | echo "$@" | grep -q -- '--repair'; then
30 | dir="$(dirname ${@: -1})"
31 | if [ -f ${dir}/${beacon} ]; then
32 | return 1;
33 | fi
34 | return 0;
35 | fi
36 | return 1
37 | }
38 |
--------------------------------------------------------------------------------
/ci/actions/update-artifacts:
--------------------------------------------------------------------------------
1 | #!/bin/sh -ex
2 | # Usage: $0 tag
3 | #
4 | # Requires: gh extension 'release' installed (https://cli.github.com/manual/gh_release)
5 |
6 | if [ -z "$1" ]; then
7 | echo "ERROR: needs tag where to upload the static binaries"
8 | exit 1
9 | fi
10 |
11 | type -p gh > /dev/null || { echo "ERROR: gh tool not found"; exit 1; }
12 | type -p jq > /dev/null || { echo "ERROR: jq tool not found"; exit 1; }
13 |
14 | repo="kdave/btrfs-progs"
15 |
16 | tag="$1"
17 | # TODO: verify that tag exists
18 |
19 | # Read last workflow id for master branch
20 | id=$(gh run -R "$repo" list --limit 1 --workflow 'Static binaries' --branch 'master' --json databaseId | jq '.[].databaseId')
21 |
22 | for asset in btrfs.box.static btrfs.static; do
23 | gh run -R "$repo" download "$id" -n "$asset"
24 | chmod 755 "$asset"
25 | gh release -R "$repo" upload "$tag" "$asset"
26 | done
27 |
28 | for asset in btrfs.box.static.sha256 btrfs.static.sha256; do
29 | gh run -R "$repo" download "$id" -n "$asset"
30 | gh release -R "$repo" upload "$tag" "$asset"
31 | done
32 |
--------------------------------------------------------------------------------
/ci/ci-build-musl-i386:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Usage: $0 [branch] [configure options]
3 | # Create source tarball from HEAD or given branch and build it in musl CI
4 | # environment. Configure options follow branch name that can be empty.
5 |
6 | HERE=`pwd`
7 | if [ -f "configure.ac" ]; then
8 | SOURCEDIR=`pwd`
9 | elif [ -f "../configure.ac" ]; then
10 | cd ..
11 | SOURCEDIR=`pwd`
12 | else
13 | echo "ERROR: cannot determine source directory from `pwd`"
14 | exit 1
15 | fi
16 |
17 | CIIMAGEDIR=ci/images/ci-musl-i386
18 | BRANCH=${1:-HEAD}
19 | if [ "$#" -ge 1 ]; then
20 | shift
21 | fi
22 | HASH=$(git log -1 --format='%h %s' "$BRANCH")
23 |
24 | echo "CI: Generate archive from $BRANCH ($HASH)"
25 | git archive --prefix=btrfs-progs-devel/ -o devel.tar "$BRANCH"
26 | echo "$BRANCH $HASH" > GITCOMMIT
27 | tar uvf devel.tar GITCOMMIT
28 | #rm GITCOMMIT
29 | gzip --force --best devel.tar
30 |
31 | cd "$CIIMAGEDIR"
32 | cp "$SOURCEDIR/devel.tar.gz" .
33 | ./docker-build
34 | ./docker-run -- ./test-build devel --disable-documentation --disable-backtrace --disable-libudev "$@"
35 |
--------------------------------------------------------------------------------
/ci/ci-build-centos8:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Usage: $0 [branch] [configure options]
3 | # Create source tarball from HEAD or given branch and build it in Centos 8 CI
4 | # environment. Configure options follow branch name that can be empty.
5 |
6 | HERE=`pwd`
7 | if [ -f "configure.ac" ]; then
8 | SOURCEDIR=`pwd`
9 | elif [ -f "../configure.ac" ]; then
10 | cd ..
11 | SOURCEDIR=`pwd`
12 | else
13 | echo "ERROR: cannot determine source directory from `pwd`"
14 | exit 1
15 | fi
16 |
17 | CIIMAGEDIR=ci/images/ci-centos-8-x86_64
18 | BRANCH=${1:-HEAD}
19 | if [ "$#" -ge 1 ]; then
20 | shift
21 | fi
22 | HASH=$(git log -1 --format='%h %s' "$BRANCH")
23 |
24 | echo "CI: Generate archive from $BRANCH ($HASH)"
25 | git archive --prefix=btrfs-progs-devel/ -o devel.tar "$BRANCH"
26 | echo "$BRANCH $HASH" > GITCOMMIT
27 | tar uvf devel.tar GITCOMMIT
28 | #rm GITCOMMIT
29 | gzip --force --best devel.tar
30 |
31 | cd "$CIIMAGEDIR"
32 | cp "$SOURCEDIR/devel.tar.gz" .
33 | ./docker-build
34 | ./docker-run -- ./test-build devel --disable-documentation --disable-libudev --disable-zoned "$@"
35 |
--------------------------------------------------------------------------------
/ci/ci-build-leap153:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Usage: $0 [branch] [configure options]
3 | # Create source tarball from HEAD or given branch and build it in openSUSE Leap 15.3 CI
4 | # environment. Configure options follow branch name that can be empty.
5 |
6 | HERE=`pwd`
7 | if [ -f "configure.ac" ]; then
8 | SOURCEDIR=`pwd`
9 | elif [ -f "../configure.ac" ]; then
10 | cd ..
11 | SOURCEDIR=`pwd`
12 | else
13 | echo "ERROR: cannot determine source directory from `pwd`"
14 | exit 1
15 | fi
16 |
17 | CIIMAGEDIR=ci/images/ci-openSUSE-Leap-15.3-x86_64
18 | BRANCH=${1:-HEAD}
19 | if [ "$#" -ge 1 ]; then
20 | shift
21 | fi
22 | HASH=$(git log -1 --format='%h %s' "$BRANCH")
23 |
24 | echo "CI: Generate archive from $BRANCH ($HASH)"
25 | git archive --prefix=btrfs-progs-devel/ -o devel.tar "$BRANCH"
26 | echo "$BRANCH $HASH" > GITCOMMIT
27 | tar uvf devel.tar GITCOMMIT
28 | #rm GITCOMMIT
29 | gzip --force --best devel.tar
30 |
31 | cd "$CIIMAGEDIR"
32 | cp "$SOURCEDIR/devel.tar.gz" .
33 | ./docker-build
34 | ./docker-run -- ./test-build devel --disable-documentation --disable-zoned "$@"
35 |
--------------------------------------------------------------------------------
/ci/ci-build-leap156:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Usage: $0 [branch] [configure options]
3 | # Create source tarball from HEAD or given branch and build it in openSUSE Leap 15.6 CI
4 | # environment. Configure options follow branch name that can be empty.
5 |
6 | HERE=`pwd`
7 | if [ -f "configure.ac" ]; then
8 | SOURCEDIR=`pwd`
9 | elif [ -f "../configure.ac" ]; then
10 | cd ..
11 | SOURCEDIR=`pwd`
12 | else
13 | echo "ERROR: cannot determine source directory from `pwd`"
14 | exit 1
15 | fi
16 |
17 | CIIMAGEDIR=ci/images/ci-openSUSE-Leap-15.6-x86_64
18 | BRANCH=${1:-HEAD}
19 | if [ "$#" -ge 1 ]; then
20 | shift
21 | fi
22 | HASH=$(git log -1 --format='%h %s' "$BRANCH")
23 |
24 | echo "CI: Generate archive from $BRANCH ($HASH)"
25 | git archive --prefix=btrfs-progs-devel/ -o devel.tar "$BRANCH"
26 | echo "$BRANCH $HASH" > GITCOMMIT
27 | tar uvf devel.tar GITCOMMIT
28 | #rm GITCOMMIT
29 | gzip --force --best devel.tar
30 |
31 | cd "$CIIMAGEDIR"
32 | cp "$SOURCEDIR/devel.tar.gz" .
33 | ./docker-build
34 | ./docker-run -- ./test-build devel --disable-documentation --disable-zoned "$@"
35 |
--------------------------------------------------------------------------------
/tests/cli-tests/005-qgroup-show/test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # qgroup show behaviour when quotas are not enabled
4 |
5 | source "$TEST_TOP/common" || exit
6 |
7 | check_prereq mkfs.btrfs
8 | check_prereq btrfs
9 |
10 | setup_root_helper
11 | prepare_test_dev
12 |
13 | run_check_mkfs_test_dev
14 | run_check_mount_test_dev
15 | run_mayfail "$TOP/btrfs" qgroup show "$TEST_MNT"
16 | run_mayfail "$TOP/btrfs" --format json qgroup show "$TEST_MNT"
17 | run_mayfail $SUDO_HELPER "$TOP/btrfs" qgroup show "$TEST_MNT"
18 | run_mayfail $SUDO_HELPER "$TOP/btrfs" --format json qgroup show "$TEST_MNT"
19 | run_check $SUDO_HELPER "$TOP/btrfs" quota enable "$TEST_MNT"
20 | run_check $SUDO_HELPER "$TOP/btrfs" qgroup limit 128m "$TEST_MNT"
21 | run_mayfail "$TOP/btrfs" qgroup show "$TEST_MNT"
22 | run_mayfail "$TOP/btrfs" --format json qgroup show "$TEST_MNT"
23 | run_check $SUDO_HELPER "$TOP/btrfs" qgroup show "$TEST_MNT"
24 | run_check $SUDO_HELPER "$TOP/btrfs" --format json qgroup show "$TEST_MNT"
25 | run_check $SUDO_HELPER "$TOP/btrfs" quota disable "$TEST_MNT"
26 | run_check_umount_test_dev
27 |
--------------------------------------------------------------------------------
/.github/workflows/test.yml:
--------------------------------------------------------------------------------
1 | # Testing workflow for CI developments, reacts to push of branch 'devel-ci'
2 | name: Testing CI build
3 | run-name: Testing CI
4 | on:
5 | push:
6 | branches:
7 | - devel-ci
8 | jobs:
9 | build:
10 | runs-on: ubuntu-24.04
11 | steps:
12 | - uses: actions/checkout@v4
13 | - run: uname -a
14 | - run: sudo modprobe btrfs
15 | - run: cat /proc/filesystems
16 | - run: gcc --version
17 | - run: df -HT
18 | - run: sudo apt-get update -qqq
19 | - run: sudo apt-get install -y pkg-config gcc liblzo2-dev libzstd-dev libblkid-dev uuid-dev zlib1g-dev libext2fs-dev e2fsprogs libudev-dev python3-sphinx libaio-dev liburing-dev
20 | - name: Configure
21 | run: ./autogen.sh && ./configure
22 | - name: Make
23 | run: make V=1
24 | - name: Musl build
25 | run: sudo docker run kdave/ci-musl-x86_64 ./test-build $GITHUB_REF_NAME --disable-documentation --disable-backtrace --disable-libudev
26 | - name: Tests cli
27 | run: echo sudo make TEST_LOG=dump test-cli
28 |
--------------------------------------------------------------------------------
/common/extent-tree-utils.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This program is free software; you can redistribute it and/or
3 | * modify it under the terms of the GNU General Public
4 | * License v2 as published by the Free Software Foundation.
5 | *
6 | * This program is distributed in the hope that it will be useful,
7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 | * General Public License for more details.
10 | *
11 | * You should have received a copy of the GNU General Public
12 | * License along with this program; if not, write to the
13 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
14 | * Boston, MA 021110-1307, USA.
15 | */
16 |
17 | #ifndef _EXTENT_TREE_UTILS_H_
18 | #define _EXTENT_TREE_UTILS_H_
19 |
20 | #include "kerncompat.h"
21 |
22 | struct btrfs_inode_item;
23 | struct btrfs_path;
24 | struct btrfs_root;
25 | struct btrfs_trans_handle;
26 |
27 | int btrfs_next_extent_item(struct btrfs_root *root, struct btrfs_path *path,
28 | u64 max_objectid);
29 |
30 | #endif
31 |
--------------------------------------------------------------------------------
/tests/cli-tests/017-fi-show-missing/test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Test that if a device is missing for a mounted filesystem, btrfs fi show will
4 | # show which device exactly is missing.
5 |
6 | source "$TEST_TOP/common" || exit
7 |
8 | check_prereq mkfs.btrfs
9 | check_prereq btrfs
10 |
11 | setup_root_helper
12 | setup_loopdevs 2
13 | prepare_loopdevs
14 |
15 | dev1=${loopdevs[1]}
16 | dev2=${loopdevs[2]}
17 |
18 | run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -d raid1 "${loopdevs[@]}"
19 |
20 | # Move the device, changing its path, simulating the device being missing
21 | run_check $SUDO_HELPER mv "$dev2" /dev/loop-non-existent
22 |
23 | cond_wait_for_loopdevs
24 | run_check $SUDO_HELPER mount -o degraded "$dev1" "$TEST_MNT"
25 |
26 | if ! run_check_stdout $SUDO_HELPER "$TOP/btrfs" filesystem show "$TEST_MNT" | \
27 | grep -q -e "devid[[:space:]]\+2.*MISSING"; then
28 |
29 | _fail "didn't find exact missing device"
30 | fi
31 |
32 | run_check $SUDO_HELPER mv /dev/loop-non-existent "$dev2"
33 |
34 | run_check $SUDO_HELPER umount "$TEST_MNT"
35 |
36 | cleanup_loopdevs
37 |
--------------------------------------------------------------------------------
/Documentation/ch-flexibility.rst:
--------------------------------------------------------------------------------
1 | The underlying design of BTRFS data structures allows a lot of flexibility and
2 | making changes after filesystem creation, like resizing, adding/removing space
3 | or enabling some features on-the-fly.
4 |
5 | * **dynamic inode creation** -- there's no fixed space or tables for tracking
6 | inodes so the number of inodes that can be created is bounded by the metadata
7 | space and its utilization
8 |
9 | * **block group profile change on-the-fly** -- the block group profiles can be
10 | changed on a mounted filesystem by running the balance operation and
11 | specifying the conversion filters (see :doc:`balance`)
12 |
13 | * **resize** -- the space occupied by the filesystem on each device can be
14 | resized up (grow) or down (shrink) as long as the amount of data can be still
15 | contained on the device
16 |
17 | * **device management** -- devices can be added, removed or replaced without
18 | requiring recreating the filesystem (mkfs), new redundancy options available
19 | on more devices can be also utilized by rebalancing
20 |
--------------------------------------------------------------------------------
/common/inject-error.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This program is free software; you can redistribute it and/or
3 | * modify it under the terms of the GNU General Public
4 | * License v2 as published by the Free Software Foundation.
5 | *
6 | * This program is distributed in the hope that it will be useful,
7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 | * General Public License for more details.
10 | *
11 | * You should have received a copy of the GNU General Public
12 | * License along with this program; if not, write to the
13 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
14 | * Boston, MA 021110-1307, USA.
15 | */
16 |
17 | #ifndef __INJECT_ERROR_H__
18 | #define __INJECT_ERROR_H__
19 |
20 | #include
21 |
22 | #ifdef INJECT
23 |
24 | #define inject_error(cookie) __inject_error((cookie), __FILE__, __LINE__)
25 | bool __inject_error(unsigned long cookie, const char *file, int line);
26 |
27 | #else
28 |
29 | #define inject_error(cookie) (false)
30 |
31 | #endif
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/crypto/crc32c.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 Red Hat. All rights reserved.
3 | *
4 | * This program is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU General Public
6 | * License v2 as published by the Free Software Foundation.
7 | *
8 | * This program is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 | * General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public
14 | * License along with this program; if not, write to the
15 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 | * Boston, MA 021110-1307, USA.
17 | */
18 |
19 | #ifndef __CRC32C__
20 | #define __CRC32C__
21 |
22 | #include
23 |
24 | uint32_t crc32c_le(uint32_t seed, unsigned char const *data, uint32_t length);
25 | void crc32c_init_accel(void);
26 |
27 | #define crc32c(seed, data, length) crc32c_le(seed, (unsigned char const *)data, length)
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/tests/convert-tests/027-large-symbolic-link/test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Make sure btrfs-convert can handle a symbolic link which is 4095 bytes long
3 |
4 | source "$TEST_TOP/common" || exit
5 | source "$TEST_TOP/common.convert" || exit
6 |
7 | setup_root_helper
8 | prepare_test_dev 1G
9 | check_global_prereq mkfs.ext4
10 |
11 | # This is at the symbolic link size limit (PATH_MAX includes the terminating NUL).
12 | link_target=$(printf "%0.sb" {1..4095})
13 |
14 | convert_test_prep_fs ext4 mke2fs -t ext4 -b 4096
15 | run_check $SUDO_HELPER ln -s "$link_target" "$TEST_MNT/symbolic_link"
16 | run_check_umount_test_dev
17 |
18 | # For unpatched btrfs-convert, it will always append one byte to the
19 | # link target, causing the above 4095 target to be 4096, exactly one sector,
20 | # resulting in a regular file extent.
21 | convert_test_do_convert
22 |
23 | run_check_mount_test_dev
24 | # If the unpatched btrfs-convert created a regular extent, and the kernel is
25 | # new enough, readlink will be rejected by kernel.
26 | run_check $SUDO_HELPER readlink "$TEST_MNT/symbolic_link"
27 | run_check_umount_test_dev
28 |
--------------------------------------------------------------------------------
/Documentation/man-preview.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Generate manual page preview as rendered to a terminal, without colors or
3 | # text attributes, encapsulated html, usable for CI summary
4 |
5 | if ! [ -f "$1" ]; then
6 | exit 0
7 | fi
8 |
9 | width=120
10 | prefix=Documentation/
11 | here=$(pwd)
12 |
13 | if [ "$(basename \"$here\")" = 'Documentation' ]; then
14 | prefix=
15 | fi
16 |
17 | fn="$1"
18 | bn=$(basename "$fn" .rst)
19 |
20 | if [ "$bn" = 'btrfs-man5' ]; then
21 | # This is the only page that does not follow from the file name,
22 | # the translation could be done using the man_pages table in conf.py
23 | # but for one entry let's add a exception here
24 | man="${prefix}_build/man/btrfs.5"
25 | else
26 | man=$(find "${prefix}"_build/man -name "$bn".'[0-9]')
27 | fi
28 |
29 | if ! [ -f "$man" ]; then
30 | #echo "ERROR: cannot find manual page '$man' from bn $bn fn $fn
"
31 | exit 0
32 | fi
33 |
34 | cat << EOF
35 |
36 | $fn
37 |
38 | \`\`\`
39 | EOF
40 |
41 | COLUMNS="$width" man -P cat "$man"
42 |
43 | cat << EOF
44 | \`\`\`
45 |
46 |
47 | EOF
48 |
--------------------------------------------------------------------------------
/libbtrfs/crc32c.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 Red Hat. All rights reserved.
3 | *
4 | * This program is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU General Public
6 | * License v2 as published by the Free Software Foundation.
7 | *
8 | * This program is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 | * General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public
14 | * License along with this program; if not, write to the
15 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 | * Boston, MA 021110-1307, USA.
17 | */
18 |
19 | #ifndef __CRC32C__
20 | #define __CRC32C__
21 |
22 | #include
23 |
24 | uint32_t crc32c_le(uint32_t seed, unsigned char const *data, uint32_t length);
25 | void crc32c_optimization_init(void);
26 |
27 | #define crc32c(seed, data, length) crc32c_le(seed, (unsigned char const *)data, length)
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/tests/fsck-tests/060-degraded-check/test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Make sure "btrfs check" can handle degraded raid5.
4 | #
5 |
6 | source "$TEST_TOP/common" || exit
7 |
8 | check_prereq btrfs
9 | check_prereq mkfs.btrfs
10 | check_global_prereq losetup
11 | check_global_prereq wipefs
12 |
13 | setup_root_helper
14 |
15 | setup_loopdevs 3
16 | prepare_loopdevs
17 | dev1=${loopdevs[1]}
18 | dev2=${loopdevs[2]}
19 | dev3=${loopdevs[3]}
20 |
21 | # Run 1: victim is dev1
22 | run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -m raid5 -d raid5 "${loopdevs[@]}"
23 | run_check $SUDO_HELPER wipefs -fa "$dev1"
24 | run_check $SUDO_HELPER "$TOP/btrfs" check "$dev2"
25 |
26 | # Run 2: victim is dev2
27 | run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -m raid5 -d raid5 "${loopdevs[@]}"
28 | run_check $SUDO_HELPER wipefs -fa "$dev2"
29 | run_check $SUDO_HELPER "$TOP/btrfs" check "$dev3"
30 |
31 | # Run 3: victim is dev3
32 | run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -m raid5 -d raid5 "${loopdevs[@]}"
33 | run_check $SUDO_HELPER wipefs -fa "$dev3"
34 | run_check $SUDO_HELPER "$TOP/btrfs" check "$dev1"
35 |
36 | cleanup_loopdevs
37 |
--------------------------------------------------------------------------------
/tests/cli-tests/011-defrag-recursion/test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # check how deep does recursive defrag go, currently it has to stop at
3 | # mountpoint and subvolume boundary, ie. only the first file should
4 | # appear in the list of processed files
5 |
6 | source "$TEST_TOP/common" || exit
7 |
8 | check_prereq mkfs.btrfs
9 | check_prereq btrfs
10 |
11 | setup_root_helper
12 | prepare_test_dev
13 |
14 | run_check_mkfs_test_dev
15 | run_check_mount_test_dev
16 |
17 | run_check $SUDO_HELPER dd if=/dev/zero bs=1M count=10 of="$TEST_MNT"/file1
18 | run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT"/subv1
19 | run_check $SUDO_HELPER dd if=/dev/zero bs=1M count=10 of="$TEST_MNT"/subv1/file2
20 | run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot "$TEST_MNT"/subv1 "$TEST_MNT"/snap1
21 | run_check $SUDO_HELPER dd if=/dev/zero bs=1M count=10 of="$TEST_MNT"/snap1/file3
22 |
23 | run_check $SUDO_HELPER find "$TEST_MNT"
24 | run_check_stdout $SUDO_HELPER "$TOP/btrfs" filesystem defrag -v -r "$TEST_MNT" |
25 | grep -q 'file[23]' && _fail "recursive defrag went to subvolumes"
26 |
27 | run_check_umount_test_dev
28 |
--------------------------------------------------------------------------------
/tests/mkfs-tests/026-extent-tree-to-bgt/test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Test back and forth conversion from extent tree to block-group-tree
3 |
4 | source "$TEST_TOP/common" || exit
5 |
6 | setup_root_helper
7 | prepare_test_dev
8 |
9 | run_check_mkfs_test_dev -O ^block-group-tree
10 | run_check_mount_test_dev
11 | run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT"/file bs=1M count=1
12 | run_check_umount_test_dev
13 |
14 | run_check "$TOP/btrfs" inspect-internal dump-tree "$TEST_DEV"
15 | run_check "$TOP/btrfs" inspect-internal dump-super "$TEST_DEV"
16 | run_check "$TOP/btrfstune" --convert-to-block-group-tree "$TEST_DEV"
17 | _log "=== AFTER CONVERSION ==="
18 | run_check "$TOP/btrfs" inspect-internal dump-tree "$TEST_DEV"
19 | run_check "$TOP/btrfs" inspect-internal dump-super "$TEST_DEV"
20 | run_check "$TOP/btrfs" check "$TEST_DEV"
21 | _log "=== BACK CONVERSION ==="
22 | run_check "$TOP/btrfstune" --convert-from-block-group-tree "$TEST_DEV"
23 | run_check "$TOP/btrfs" inspect-internal dump-tree "$TEST_DEV"
24 | run_check "$TOP/btrfs" inspect-internal dump-super "$TEST_DEV"
25 | run_check "$TOP/btrfs" check "$TEST_DEV"
26 |
--------------------------------------------------------------------------------
/tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # iterate over nodesize and sectorsize combinations
3 |
4 | source "$TEST_TOP/common" || exit
5 |
6 | check_prereq mkfs.btrfs
7 | check_prereq btrfs
8 |
9 | setup_root_helper
10 | prepare_test_dev
11 |
12 | test_mkfs_single()
13 | {
14 | run_check_mkfs_test_dev "$@"
15 | run_check $SUDO_HELPER "$TOP/btrfs" inspect-internal dump-super "$TEST_DEV"
16 | run_check $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV"
17 | }
18 |
19 | # default
20 | test_mkfs_single
21 |
22 | # nodesize >= sectorsize
23 | for nodesize in 4096 8192 16384 32768 65536; do
24 | for sectorsize in 4096 8192 16384 32768 65536; do
25 | [ "$nodesize" -lt "$sectorsize" ] && continue
26 | test_mkfs_single -n "$nodesize" -s "$sectorsize" -d single -m single
27 | test_mkfs_single -n "$nodesize" -s "$sectorsize" -d single -m dup
28 | done
29 | done
30 |
31 | # nodesize, mixed mode
32 | for nodesize in 4k 8k 16k 32k 64k; do
33 | test_mkfs_single -n "$nodesize" -s "$nodesize" -d single -m single --mixed
34 | test_mkfs_single -n "$nodesize" -s "$nodesize" -d dup -m dup --mixed
35 | done
36 |
--------------------------------------------------------------------------------
/tests/mkfs-tests/034-rootdir-extra-hard-links/test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Test if "mkfs.btrfs --rootdir" would handle hard links where one is inside
4 | # the rootdir, the other out of the rootdir.
5 |
6 | source "$TEST_TOP/common" || exit
7 |
8 | prepare_test_dev
9 |
10 | tmpdir=$(_mktemp_dir mkfs-rootdir-hardlinks)
11 |
12 | run_check mkdir "$tmpdir/rootdir"
13 | run_check touch "$tmpdir/rootdir/inside_link"
14 | run_check ln "$tmpdir/rootdir/inside_link" "$tmpdir/outside_link"
15 |
16 | # Add more links to trigger the warnings
17 | run_check touch "$tmpdir/rootdir/link0"
18 | for i in {1..10}; do
19 | run_check ln "$tmpdir/rootdir/link0" "$tmpdir/rootdir/link$i"
20 | done
21 |
22 | run_check_mkfs_test_dev --rootdir "$tmpdir/rootdir"
23 |
24 | # For older mkfs.btrfs --rootdir we will create inside_link with 2 links,
25 | # but since the other one is out of the rootdir, there should only be one
26 | # 1 link, leading to btrfs check fail.
27 | #
28 | # The new behavior will split all hard links into different inodes, thus
29 | # have correct nlink for each new inode.
30 | run_check $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV"
31 |
--------------------------------------------------------------------------------
/tests/mkfs-tests/020-basic-checksums-mount/test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Test creating images with all supported checksums followed by mount
4 |
5 | source "$TEST_TOP/common" || exit
6 |
7 | check_prereq mkfs.btrfs
8 | check_prereq btrfs
9 |
10 | setup_root_helper
11 | prepare_test_dev
12 |
13 | if ! [ -f "/sys/fs/btrfs/features/supported_checksums" ]; then
14 | _not_run "kernel support for checksums missing"
15 | fi
16 |
17 | test_mkfs_mount_checksum()
18 | {
19 | local csum
20 |
21 | csum="$1"
22 | run_check_stdout $SUDO_HELPER "$TOP/mkfs.btrfs" -f --csum "$csum" "$TEST_DEV" | grep -q "Checksum:.*$csum"
23 | run_check $SUDO_HELPER "$TOP/btrfs" inspect-internal dump-super "$TEST_DEV"
24 | run_check $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV"
25 |
26 | run_check_mount_test_dev
27 | run_check "$TOP/btrfs" filesystem df "$TEST_MNT"
28 | run_check $SUDO_HELPER "$TOP/btrfs" filesystem usage "$TEST_MNT"
29 | run_check $SUDO_HELPER "$TOP/btrfs" device usage "$TEST_MNT"
30 | run_check_umount_test_dev
31 | }
32 |
33 | for csum in $(cat /sys/fs/btrfs/features/supported_checksums); do
34 | test_mkfs_mount_checksum "$csum"
35 | done
36 |
--------------------------------------------------------------------------------
/Documentation/Custom-ioctls.rst:
--------------------------------------------------------------------------------
1 | Custom ioctls
2 | =============
3 |
4 | Filesystems are usually extended by custom ioctls beyond the standard system
5 | call interface to let user applications access the advanced features. They're
6 | low level and the following list gives only an overview of the capabilities or
7 | a command if available:
8 |
9 | - reverse lookup, from file offset to inode, as command :command:`btrfs inspect-internal logical-resolve`
10 |
11 | - resolve inode number to list of names, as command :command:`btrfs inspect-internal inode-resolve`
12 |
13 | - tree search, given a key range and tree id, lookup and return all b-tree items
14 | found in that range, basically all metadata at your hand but you need to know
15 | what to do with them, the ioctl is privileged as it has full access to all
16 | filesystem metadata
17 |
18 | - informative, about devices, space allocation or the whole filesystem, many of
19 | which is also exported in :file:`/sys/fs/btrfs/`
20 |
21 | - query/set a subset of features on a mounted filesystem
22 |
23 | Programming documentation of the ioctls is in the manual page
24 | :doc:`btrfs-ioctl`.
25 |
--------------------------------------------------------------------------------
/image/common.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This program is free software; you can redistribute it and/or
3 | * modify it under the terms of the GNU General Public
4 | * License v2 as published by the Free Software Foundation.
5 | *
6 | * This program is distributed in the hope that it will be useful,
7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 | * General Public License for more details.
10 | *
11 | * You should have received a copy of the GNU General Public
12 | * License along with this program; if not, write to the
13 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
14 | * Boston, MA 021110-1307, USA.
15 | */
16 |
17 | #ifndef __BTRFS_IMAGE_COMMON_H__
18 | #define __BTRFS_IMAGE_COMMON_H__
19 |
20 | #include "kerncompat.h"
21 | #include
22 |
23 | struct btrfs_fs_info;
24 |
25 | void csum_block(u8 *buf, size_t len);
26 | int detect_version(FILE *in);
27 | int update_disk_super_on_device(struct btrfs_fs_info *info,
28 | const char *other_dev, u64 cur_devid);
29 | void write_backup_supers(int fd, u8 *buf);
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/tests/mkfs-tests/018-multidevice-overflow/test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # test if mkfs.btrfs will create file systems that overflow total_bytes
3 |
4 | source "$TEST_TOP/common" || exit
5 |
6 | check_prereq mkfs.btrfs
7 | check_prereq btrfs
8 |
9 | setup_root_helper
10 | prepare_test_dev
11 |
12 | # create a temporary btrfs filesystem for the images to make sure the
13 | # exabyte-scale files will be reliably created
14 | run_check_mkfs_test_dev
15 | run_check_mount_test_dev
16 |
17 | # truncate can fail with EFBIG if the OS cannot create a 6EiB file
18 | out=$(run_mayfail_stdout $SUDO_HELPER truncate -s 6E "$TEST_MNT/img1" 2>&1)
19 | ret=$?
20 |
21 | if [ $ret -ne 0 ]; then
22 | run_check_umount_test_dev
23 | if [[ "$out" == *"File too large"* ]]; then
24 | _not_run "current kernel could not create a 6EiB file"
25 | fi
26 | _fail "command 'truncate -s 6E' failed: $out"
27 | fi
28 |
29 | run_check $SUDO_HELPER truncate -s 6E "$TEST_MNT/img2"
30 | run_check $SUDO_HELPER truncate -s 6E "$TEST_MNT/img3"
31 |
32 | run_mustfail "mkfs for too-large images" \
33 | $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_MNT"/img[123]
34 |
35 | run_check_umount_test_dev
36 |
--------------------------------------------------------------------------------
/cmds/receive-dump.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Fujitsu. All rights reserved.
3 | *
4 | * This program is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU General Public
6 | * License v2 as published by the Free Software Foundation.
7 | *
8 | * This program is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 | * General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public
14 | * License along with this program; if not, write to the
15 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 | * Boston, MA 021110-1307, USA.
17 | */
18 |
19 | #ifndef __BTRFS_SEND_DUMP_H__
20 | #define __BTRFS_SEND_DUMP_H__
21 |
22 | #include
23 | #include
24 | #include "common/send-stream.h"
25 |
26 | struct btrfs_dump_send_args {
27 | char full_subvol_path[PATH_MAX];
28 | char root_path[PATH_MAX];
29 | };
30 |
31 | extern struct btrfs_send_ops btrfs_print_send_ops;
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/common/filesystem-utils.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This program is free software; you can redistribute it and/or
3 | * modify it under the terms of the GNU General Public
4 | * License v2 as published by the Free Software Foundation.
5 | *
6 | * This program is distributed in the hope that it will be useful,
7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 | * General Public License for more details.
10 | *
11 | * You should have received a copy of the GNU General Public
12 | * License along with this program; if not, write to the
13 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
14 | * Boston, MA 021110-1307, USA.
15 | */
16 |
17 | #ifndef __BTRFS_FILESYSTEM_UTILS_H__
18 | #define __BTRFS_FILESYSTEM_UTILS_H__
19 |
20 | #include "kerncompat.h"
21 |
22 | int lookup_path_rootid(int fd, u64 *rootid);
23 | int get_label(const char *btrfs_dev, char *label);
24 | int set_label(const char *btrfs_dev, const char *label);
25 | int get_label_mounted(const char *mount_path, char *labelp);
26 | int get_label_unmounted(const char *dev, char *label);
27 |
28 | #endif
29 |
--------------------------------------------------------------------------------
/tests/scan-results.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Look for some frequent error message templates in test logs
3 | #
4 | # Usage: $0 [test-log.txt]
5 |
6 | ret=0
7 |
8 | scan_log() {
9 | local file="$1"
10 |
11 | echo "Scanning $file"
12 | last=
13 | while read line; do
14 | case "$line" in
15 | ===\ START\ TEST*) last="$line" ;;
16 | *Assertion*failed*) ret=1; echo "ASSERTION FAILED: $last" ;;
17 | *runtime\ error*) ret=1; echo "RUNTIME ERROR (sanitizer): $last" ;;
18 | *AddressSanitizer*heap-use-after-free*) ret=1; echo "RUNTIME ERROR (use after free): $last" ;;
19 | *LeakSanitizer:*leak*) ret=1; echo "SANITIZER REPORT: memory leak: $last" ;;
20 | *Warning:\ assertion*failed*) ret=1; echo "ASSERTION WARNING: $last" ;;
21 | *command\ not\ found*) ret=1; echo "COMMAND NOT FOUND: $last" ;;
22 | *extent\ buffer\ leak*) ret=1; echo "EXTENT BUFFER LEAK: $last" ;;
23 | *) : ;;
24 | esac
25 | done < "$file"
26 | }
27 |
28 | # Scan only the given file
29 | if [ -n "$1" ]; then
30 | scan_log "$1"
31 | exit "$ret"
32 | fi
33 |
34 | # Scan all existing test logs
35 | for file in *.txt; do
36 | scan_log "$file"
37 | done
38 |
39 | exit "$ret"
40 |
--------------------------------------------------------------------------------