|  | 
|  | 1 | +#!/bin/bash | 
|  | 2 | +# Basic test for mkfs.btrfs --inode-flags --rootdir. Create a dataset and use it as | 
|  | 3 | +# rootdir, then various inode-flags and verify the flag is properly set. | 
|  | 4 | + | 
|  | 5 | +source "$TEST_TOP/common" || exit | 
|  | 6 | + | 
|  | 7 | +check_prereq mkfs.btrfs | 
|  | 8 | +check_prereq btrfs | 
|  | 9 | +check_global_prereq lsattr | 
|  | 10 | + | 
|  | 11 | +setup_root_helper | 
|  | 12 | +prepare_test_dev | 
|  | 13 | + | 
|  | 14 | +tmp=$(_mktemp_dir mkfs-rootdir) | 
|  | 15 | + | 
|  | 16 | +write_file() | 
|  | 17 | +{ | 
|  | 18 | +	local path="$1" | 
|  | 19 | +	local size="$2" | 
|  | 20 | + | 
|  | 21 | +	run_check dd if=/dev/zero of="$path" bs="$size" count=1 status=noxfer > /dev/null 2>&1 | 
|  | 22 | +} | 
|  | 23 | + | 
|  | 24 | +check_nodatacow() | 
|  | 25 | +{ | 
|  | 26 | +	local path="$1" | 
|  | 27 | + | 
|  | 28 | +	lsattr "$TEST_MNT/$path" | grep -q C || _fail "missing NODATACOW flag for $path" | 
|  | 29 | +} | 
|  | 30 | + | 
|  | 31 | +write_file "$tmp/file1" 64K | 
|  | 32 | +write_file "$tmp/file2" 64K | 
|  | 33 | +run_check mkdir -p "$tmp/subv" "$tmp/nocow_subv" "$tmp/nocow_dir/dir2" | 
|  | 34 | +write_file "$tmp/subv/file3" 64K | 
|  | 35 | +write_file "$tmp/nocow_subv/file4" 64K | 
|  | 36 | +write_file "$tmp/nocow_dir/dir2/file5" 64K | 
|  | 37 | +write_file "$tmp/nocow_dir/file6" 64K | 
|  | 38 | +write_file "$tmp/nocow_file1" 64K | 
|  | 39 | + | 
|  | 40 | +run_check_mkfs_test_dev --rootdir "$tmp"	\ | 
|  | 41 | +	--inode-flags "nodatacow:nocow_subv"	\ | 
|  | 42 | +	--subvol "nocow_subv"			\ | 
|  | 43 | +	--inode-flags "nodatacow:nocow_dir"	\ | 
|  | 44 | +	--inode-flags "nodatacow:nocow_file1" | 
|  | 45 | + | 
|  | 46 | +run_check $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV" | 
|  | 47 | + | 
|  | 48 | +run_check_mount_test_dev | 
|  | 49 | +check_nodatacow "nocow_subv" | 
|  | 50 | +check_nodatacow "nocow_subv/file4" | 
|  | 51 | +check_nodatacow "nocow_dir" | 
|  | 52 | +check_nodatacow "nocow_dir/file6" | 
|  | 53 | +check_nodatacow "nocow_dir/dir2/file5" | 
|  | 54 | +check_nodatacow "nocow_file1" | 
|  | 55 | +run_check lsattr -R "$TEST_MNT" | 
|  | 56 | +run_check_umount_test_dev | 
|  | 57 | + | 
|  | 58 | +run_check rm -rf -- "$tmp" | 
0 commit comments