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