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