xref: /aosp_15_r20/external/ltp/testcases/kernel/fs/iso9660/isofs.sh (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker#!/bin/sh
2*49cdfc7eSAndroid Build Coastguard Worker# SPDX-License-Identifier: GPL-2.0-or-later
3*49cdfc7eSAndroid Build Coastguard Worker# Copyright (c) International Business Machines Corp., 2003
4*49cdfc7eSAndroid Build Coastguard Worker# Copyright (c) Linux Test Project, 2016-2024
5*49cdfc7eSAndroid Build Coastguard Worker# Written by Prakash Narayana ([email protected])
6*49cdfc7eSAndroid Build Coastguard Worker# and Michael Reed ([email protected])
7*49cdfc7eSAndroid Build Coastguard Worker#
8*49cdfc7eSAndroid Build Coastguard Worker# Test isofs on Linux system.
9*49cdfc7eSAndroid Build Coastguard Worker# It makes ISO9660 file system with different options and also
10*49cdfc7eSAndroid Build Coastguard Worker# mounts ISO9660 file system with different mount options.
11*49cdfc7eSAndroid Build Coastguard Worker
12*49cdfc7eSAndroid Build Coastguard WorkerTST_NEEDS_CMDS="mount umount"
13*49cdfc7eSAndroid Build Coastguard WorkerTST_NEEDS_TMPDIR=1
14*49cdfc7eSAndroid Build Coastguard WorkerTST_TESTFUNC=do_test
15*49cdfc7eSAndroid Build Coastguard WorkerTST_CNT=3
16*49cdfc7eSAndroid Build Coastguard Worker
17*49cdfc7eSAndroid Build Coastguard WorkerMAX_DEPTH=3
18*49cdfc7eSAndroid Build Coastguard WorkerMAX_DIRS=4
19*49cdfc7eSAndroid Build Coastguard Worker
20*49cdfc7eSAndroid Build Coastguard Workergen_fs_tree()
21*49cdfc7eSAndroid Build Coastguard Worker{
22*49cdfc7eSAndroid Build Coastguard Worker	local cur_path="$1"
23*49cdfc7eSAndroid Build Coastguard Worker	local cur_depth="$2"
24*49cdfc7eSAndroid Build Coastguard Worker	local i new_path
25*49cdfc7eSAndroid Build Coastguard Worker
26*49cdfc7eSAndroid Build Coastguard Worker	[ "$cur_depth" -gt "$MAX_DEPTH" ] && return
27*49cdfc7eSAndroid Build Coastguard Worker
28*49cdfc7eSAndroid Build Coastguard Worker	for i in $(seq 1 $MAX_DIRS); do
29*49cdfc7eSAndroid Build Coastguard Worker		new_path="$cur_path/subdir_$i"
30*49cdfc7eSAndroid Build Coastguard Worker		mkdir -p "$new_path"
31*49cdfc7eSAndroid Build Coastguard Worker		ROD_SILENT dd if=/dev/urandom of="$new_path/file" bs=1024 count=100
32*49cdfc7eSAndroid Build Coastguard Worker		gen_fs_tree "$new_path" $((cur_depth + 1))
33*49cdfc7eSAndroid Build Coastguard Worker	done
34*49cdfc7eSAndroid Build Coastguard Worker}
35*49cdfc7eSAndroid Build Coastguard Worker
36*49cdfc7eSAndroid Build Coastguard Workerdo_test()
37*49cdfc7eSAndroid Build Coastguard Worker{
38*49cdfc7eSAndroid Build Coastguard Worker	local mnt_point="$PWD/mnt"
39*49cdfc7eSAndroid Build Coastguard Worker	local make_file_sys_dir="$PWD/files"
40*49cdfc7eSAndroid Build Coastguard Worker	local mkisofs_opt mount_opt
41*49cdfc7eSAndroid Build Coastguard Worker
42*49cdfc7eSAndroid Build Coastguard Worker	case $1 in
43*49cdfc7eSAndroid Build Coastguard Worker		1) MKISOFS_CMD="mkisofs"
44*49cdfc7eSAndroid Build Coastguard Worker			HFSOPT="-hfs -D"
45*49cdfc7eSAndroid Build Coastguard Worker			GREPOPT="mkisofs";;
46*49cdfc7eSAndroid Build Coastguard Worker		2) MKISOFS_CMD="genisoimage"
47*49cdfc7eSAndroid Build Coastguard Worker			HFSOPT="-hfsplus -D -hfs -D"
48*49cdfc7eSAndroid Build Coastguard Worker			GREPOPT="genisoimage";;
49*49cdfc7eSAndroid Build Coastguard Worker		3) MKISOFS_CMD="xorrisofs"
50*49cdfc7eSAndroid Build Coastguard Worker			HFSOPT="-hfsplus -D"
51*49cdfc7eSAndroid Build Coastguard Worker			GREPOPT="xorriso";;
52*49cdfc7eSAndroid Build Coastguard Worker	esac
53*49cdfc7eSAndroid Build Coastguard Worker
54*49cdfc7eSAndroid Build Coastguard Worker	if ! tst_cmd_available $MKISOFS_CMD; then
55*49cdfc7eSAndroid Build Coastguard Worker		tst_res TCONF "Missing '$MKISOFS_CMD'"
56*49cdfc7eSAndroid Build Coastguard Worker		return
57*49cdfc7eSAndroid Build Coastguard Worker	fi
58*49cdfc7eSAndroid Build Coastguard Worker
59*49cdfc7eSAndroid Build Coastguard Worker	if ! $MKISOFS_CMD 2>&1 | head -n 2 | grep -q "$GREPOPT"; then
60*49cdfc7eSAndroid Build Coastguard Worker		tst_res TCONF "'$MKISOFS_CMD' is a symlink to another tool"
61*49cdfc7eSAndroid Build Coastguard Worker		return
62*49cdfc7eSAndroid Build Coastguard Worker	fi
63*49cdfc7eSAndroid Build Coastguard Worker
64*49cdfc7eSAndroid Build Coastguard Worker	tst_res TINFO "Testing $MKISOFS_CMD"
65*49cdfc7eSAndroid Build Coastguard Worker
66*49cdfc7eSAndroid Build Coastguard Worker	mkdir -p -m 777 $mnt_point
67*49cdfc7eSAndroid Build Coastguard Worker	mkdir -p $make_file_sys_dir
68*49cdfc7eSAndroid Build Coastguard Worker
69*49cdfc7eSAndroid Build Coastguard Worker	mkdir -p $make_file_sys_dir
70*49cdfc7eSAndroid Build Coastguard Worker	gen_fs_tree "$make_file_sys_dir" 1
71*49cdfc7eSAndroid Build Coastguard Worker
72*49cdfc7eSAndroid Build Coastguard Worker	# Make ISO9660 file system with different options.
73*49cdfc7eSAndroid Build Coastguard Worker	# Mount the ISO9660 file system with different mount options.
74*49cdfc7eSAndroid Build Coastguard Worker	for mkisofs_opt in \
75*49cdfc7eSAndroid Build Coastguard Worker		" " \
76*49cdfc7eSAndroid Build Coastguard Worker		"-J" \
77*49cdfc7eSAndroid Build Coastguard Worker		"$HFSOPT" \
78*49cdfc7eSAndroid Build Coastguard Worker		" -R " \
79*49cdfc7eSAndroid Build Coastguard Worker		"-R -J" \
80*49cdfc7eSAndroid Build Coastguard Worker		"-f -l -D -J -allow-leading-dots -R" \
81*49cdfc7eSAndroid Build Coastguard Worker		"-allow-lowercase -allow-multidot -iso-level 3 -f -l -D -J \
82*49cdfc7eSAndroid Build Coastguard Worker			-allow-leading-dots -R"
83*49cdfc7eSAndroid Build Coastguard Worker	do
84*49cdfc7eSAndroid Build Coastguard Worker		rm -f isofs.iso
85*49cdfc7eSAndroid Build Coastguard Worker		EXPECT_PASS $MKISOFS_CMD -o isofs.iso -quiet $mkisofs_opt \
86*49cdfc7eSAndroid Build Coastguard Worker			$make_file_sys_dir 2\> /dev/null || continue
87*49cdfc7eSAndroid Build Coastguard Worker
88*49cdfc7eSAndroid Build Coastguard Worker		for mount_opt in \
89*49cdfc7eSAndroid Build Coastguard Worker			"loop" \
90*49cdfc7eSAndroid Build Coastguard Worker			"loop,norock" \
91*49cdfc7eSAndroid Build Coastguard Worker			"loop,nojoliet" \
92*49cdfc7eSAndroid Build Coastguard Worker			"loop,block=512,unhide" \
93*49cdfc7eSAndroid Build Coastguard Worker			"loop,block=1024,cruft" \
94*49cdfc7eSAndroid Build Coastguard Worker			"loop,block=2048,nocompress" \
95*49cdfc7eSAndroid Build Coastguard Worker			"loop,check=strict,map=off,gid=bin,uid=bin" \
96*49cdfc7eSAndroid Build Coastguard Worker			"loop,check=strict,map=acorn,gid=bin,uid=bin" \
97*49cdfc7eSAndroid Build Coastguard Worker			"loop,check=relaxed,map=normal" \
98*49cdfc7eSAndroid Build Coastguard Worker			"loop,block=512,unhide,session=2"
99*49cdfc7eSAndroid Build Coastguard Worker		do
100*49cdfc7eSAndroid Build Coastguard Worker			EXPECT_PASS mount -t iso9660 -o $mount_opt isofs.iso $mnt_point \
101*49cdfc7eSAndroid Build Coastguard Worker				|| continue
102*49cdfc7eSAndroid Build Coastguard Worker
103*49cdfc7eSAndroid Build Coastguard Worker			EXPECT_PASS ls -lR $mnt_point \> /dev/null
104*49cdfc7eSAndroid Build Coastguard Worker			EXPECT_PASS_BRK umount $mnt_point
105*49cdfc7eSAndroid Build Coastguard Worker
106*49cdfc7eSAndroid Build Coastguard Worker			tst_res TPASS "mount/umount with \"$mount_opt\" options"
107*49cdfc7eSAndroid Build Coastguard Worker		done
108*49cdfc7eSAndroid Build Coastguard Worker	done
109*49cdfc7eSAndroid Build Coastguard Worker}
110*49cdfc7eSAndroid Build Coastguard Worker
111*49cdfc7eSAndroid Build Coastguard Worker. tst_test.sh
112*49cdfc7eSAndroid Build Coastguard Workertst_run
113