xref: /aosp_15_r20/external/e2fsprogs/tests/m_rootdir_acl/script (revision 6a54128f25917bfc36a8a6e9d722c04a0b4641b6)
1test_description="create fs image from dir using inline_data and acls"
2if ! test -x $DEBUGFS_EXE; then
3	echo "$test_name: $test_description: skipped (no debugfs)"
4	return 0
5fi
6
7if ! setfacl --help > /dev/null 2>&1 ; then
8	echo "$test_name: $test_description: skipped (no setfacl)"
9	return 0
10fi
11
12os=$(uname -s)
13if [ "$os" = "GNU" ]; then
14	# requires Posix ACL support
15	echo "$test_name: $test_description: skipped for $os"
16	return 0
17fi
18
19MKFS_DIR=$(mktemp -d ./$test_name-XXXXXX.tmp)
20OUT=$test_name.log
21EXP=$test_dir/expect
22
23touch $MKFS_DIR/emptyfile
24dd if=/dev/zero bs=1024 count=32 2> /dev/null | tr '\0' 'a' > $MKFS_DIR/bigfile
25echo "M" | dd of=$MKFS_DIR/sparsefile bs=1 count=1 seek=1024 2> /dev/null
26echo "M" | dd of=$MKFS_DIR/sparsefile bs=1 count=1 seek=524288 conv=notrunc 2> /dev/null
27echo "M" | dd of=$MKFS_DIR/sparsefile bs=1 count=1 seek=1048576 conv=notrunc 2> /dev/null
28echo "M" | dd of=$MKFS_DIR/sparsefile bs=1 count=1 seek=536870912 conv=notrunc 2> /dev/null
29echo "M" | dd of=$MKFS_DIR/sparsefile bs=1 count=1 seek=1073741824 conv=notrunc 2> /dev/null
30dd if=/dev/zero of=$MKFS_DIR/bigzerofile bs=1 count=1 seek=1073741824 2> /dev/null
31ln $MKFS_DIR/bigzerofile $MKFS_DIR/bigzerofile_hardlink
32ln -s /silly_bs_link $MKFS_DIR/silly_bs_link
33mkdir $MKFS_DIR/emptydir
34mkdir $MKFS_DIR/dir
35echo "Test me" > $MKFS_DIR/dir/file
36mkdir $MKFS_DIR/acl_dir
37echo "Test me 2" > $MKFS_DIR/acl_dir/file
38
39setfacl --restore=- <<EOF
40# file: $MKFS_DIR/acl_dir
41user::rwx
42group::r-x
43group:42:r-x
44mask::r-x
45other::r-x
46default:user::rwx
47default:group::r-x
48default:group:4:r-x
49default:mask::r-x
50default:other::r-x
51EOF
52setfacl --restore=- <<EOF
53# file: $MKFS_DIR/acl_dir/file
54user::rwx
55group::r-x
56group:42:r-x
57mask::r-x
58other::r-x
59EOF
60
61if ! getfattr -d -m - $MKFS_DIR/acl_dir | grep -q posix_acl; then
62	echo "$test_name: $test_description: skipped (no posix_acl xattrs)"
63	rm -rf $MKFS_DIR
64	return 0
65fi
66
67# use 512-byte inodes so with/out security.selinux xattr doesn't fail
68$MKE2FS -q -F -o Linux -T ext4 -I 512 -O metadata_csum,inline_data,64bit -E lazy_itable_init=1 -b 1024 -d $MKFS_DIR $TMPFILE 16384 > $OUT 2>&1
69
70$DUMPE2FS $TMPFILE >> $OUT 2>&1
71cat > $TMPFILE.cmd << ENDL
72stat /emptyfile
73stat /bigfile
74stat /sparsefile
75stat /bigzerofile
76stat /fifo
77stat /emptydir
78stat /dir
79stat /dir/file
80stat /acl_dir
81stat /acl_dir/file
82ENDL
83$DEBUGFS -f $TMPFILE.cmd $TMPFILE 2>&1 | egrep "(stat|Size:|Type:)" >> $OUT
84
85cat > $TMPFILE.cmd << ENDL
86ea_list dir/file
87ea_list acl_dir
88ea_list acl_dir/file
89ENDL
90$DEBUGFS -f $TMPFILE.cmd $TMPFILE >> $OUT 2>&1
91
92$FSCK -f -n $TMPFILE >> $OUT 2>&1
93
94sed -f $cmd_dir/filter.sed -f $test_dir/output.sed -e "s;$TMPFILE;test.img;" < $OUT > $OUT.tmp
95mv $OUT.tmp $OUT
96
97# Do the verification
98cmp -s $OUT $EXP
99status=$?
100
101if [ "$status" = 0 ] ; then
102	echo "$test_name: $test_description: ok"
103	touch $test_name.ok
104else
105        echo "$test_name: $test_description: failed"
106        diff $DIFF_OPTS $EXP $OUT > $test_name.failed
107fi
108
109rm -rf $TMPFILE.cmd $MKFS_DIR
110unset MKFS_DIR OUT EXP
111