1f08c3bdfSopenharmony_ci#!/bin/sh
2f08c3bdfSopenharmony_ci# SPDX-License-Identifier: GPL-2.0-or-later
3f08c3bdfSopenharmony_ci# Copyright (c) International Business Machines Corp., 2003
4f08c3bdfSopenharmony_ci# Copyright (c) Linux Test Project, 2016-2021
5f08c3bdfSopenharmony_ci# Written by Prakash Narayana (prakashn@us.ibm.com)
6f08c3bdfSopenharmony_ci# and Michael Reed (mreed10@us.ibm.com)
7f08c3bdfSopenharmony_ci#
8f08c3bdfSopenharmony_ci# Test isofs on Linux system.
9f08c3bdfSopenharmony_ci# It makes ISO9660 file system with different options and also
10f08c3bdfSopenharmony_ci# mounts ISO9660 file system with different mount options.
11f08c3bdfSopenharmony_ci
12f08c3bdfSopenharmony_ciTST_NEEDS_CMDS="mount umount"
13f08c3bdfSopenharmony_ciTST_NEEDS_TMPDIR=1
14f08c3bdfSopenharmony_ciTST_SETUP=setup
15f08c3bdfSopenharmony_ciTST_TESTFUNC=do_test
16f08c3bdfSopenharmony_ci
17f08c3bdfSopenharmony_ciMAX_DEPTH=3
18f08c3bdfSopenharmony_ciMAX_DIRS=4
19f08c3bdfSopenharmony_ci
20f08c3bdfSopenharmony_cisetup()
21f08c3bdfSopenharmony_ci{
22f08c3bdfSopenharmony_ci	if tst_cmd_available mkisofs; then
23f08c3bdfSopenharmony_ci		MKISOFS_CMD="mkisofs"
24f08c3bdfSopenharmony_ci	elif tst_cmd_available genisoimage; then
25f08c3bdfSopenharmony_ci		MKISOFS_CMD="genisoimage"
26f08c3bdfSopenharmony_ci	else
27f08c3bdfSopenharmony_ci		tst_brk TCONF "please install mkisofs or genisoimage"
28f08c3bdfSopenharmony_ci	fi
29f08c3bdfSopenharmony_ci}
30f08c3bdfSopenharmony_ci
31f08c3bdfSopenharmony_cigen_fs_tree()
32f08c3bdfSopenharmony_ci{
33f08c3bdfSopenharmony_ci	local cur_path="$1"
34f08c3bdfSopenharmony_ci	local cur_depth="$2"
35f08c3bdfSopenharmony_ci	local i new_path
36f08c3bdfSopenharmony_ci
37f08c3bdfSopenharmony_ci	[ "$cur_depth" -gt "$MAX_DEPTH" ] && return
38f08c3bdfSopenharmony_ci
39f08c3bdfSopenharmony_ci	for i in $(seq 1 $MAX_DIRS); do
40f08c3bdfSopenharmony_ci		new_path="$cur_path/subdir_$i"
41f08c3bdfSopenharmony_ci		mkdir -p "$new_path"
42f08c3bdfSopenharmony_ci		ROD_SILENT dd if=/dev/urandom of="$new_path/file" bs=1024 count=100
43f08c3bdfSopenharmony_ci		gen_fs_tree "$new_path" $((cur_depth + 1))
44f08c3bdfSopenharmony_ci	done
45f08c3bdfSopenharmony_ci}
46f08c3bdfSopenharmony_ci
47f08c3bdfSopenharmony_cido_test()
48f08c3bdfSopenharmony_ci{
49f08c3bdfSopenharmony_ci	local mnt_point="$PWD/mnt"
50f08c3bdfSopenharmony_ci	local make_file_sys_dir="$PWD/files"
51f08c3bdfSopenharmony_ci	local mkisofs_opt mount_opt
52f08c3bdfSopenharmony_ci
53f08c3bdfSopenharmony_ci	mkdir -p -m 777 $mnt_point
54f08c3bdfSopenharmony_ci	mkdir -p $make_file_sys_dir
55f08c3bdfSopenharmony_ci
56f08c3bdfSopenharmony_ci	# Generated directories and files
57f08c3bdfSopenharmony_ci	mkdir -p $make_file_sys_dir
58f08c3bdfSopenharmony_ci	gen_fs_tree "$make_file_sys_dir" 1
59f08c3bdfSopenharmony_ci
60f08c3bdfSopenharmony_ci	# Make ISO9660 file system with different options.
61f08c3bdfSopenharmony_ci	# Mount the ISO9660 file system with different mount options.
62f08c3bdfSopenharmony_ci	for mkisofs_opt in \
63f08c3bdfSopenharmony_ci		" " \
64f08c3bdfSopenharmony_ci		"-J" \
65f08c3bdfSopenharmony_ci		"-hfs -D" \
66f08c3bdfSopenharmony_ci		" -R " \
67f08c3bdfSopenharmony_ci		"-R -J" \
68f08c3bdfSopenharmony_ci		"-f -l -D -J -allow-leading-dots -R" \
69f08c3bdfSopenharmony_ci		"-allow-lowercase -allow-multidot -iso-level 3 -f -l -D -J -allow-leading-dots -R"
70f08c3bdfSopenharmony_ci	do
71f08c3bdfSopenharmony_ci		rm -f isofs.iso
72f08c3bdfSopenharmony_ci		EXPECT_PASS $MKISOFS_CMD -o isofs.iso -quiet $mkisofs_opt $make_file_sys_dir 2\> /dev/null \
73f08c3bdfSopenharmony_ci			|| continue
74f08c3bdfSopenharmony_ci
75f08c3bdfSopenharmony_ci		for mount_opt in \
76f08c3bdfSopenharmony_ci			"loop" \
77f08c3bdfSopenharmony_ci			"loop,norock" \
78f08c3bdfSopenharmony_ci			"loop,nojoliet" \
79f08c3bdfSopenharmony_ci			"loop,block=512,unhide" \
80f08c3bdfSopenharmony_ci			"loop,block=1024,cruft" \
81f08c3bdfSopenharmony_ci			"loop,block=2048,nocompress" \
82f08c3bdfSopenharmony_ci			"loop,check=strict,map=off,gid=bin,uid=bin" \
83f08c3bdfSopenharmony_ci			"loop,check=strict,map=acorn,gid=bin,uid=bin" \
84f08c3bdfSopenharmony_ci			"loop,check=relaxed,map=normal" \
85f08c3bdfSopenharmony_ci			"loop,block=512,unhide,session=2"
86f08c3bdfSopenharmony_ci		do
87f08c3bdfSopenharmony_ci			EXPECT_PASS mount -t iso9660 -o $mount_opt isofs.iso $mnt_point \
88f08c3bdfSopenharmony_ci				|| continue
89f08c3bdfSopenharmony_ci
90f08c3bdfSopenharmony_ci			EXPECT_PASS ls -lR $mnt_point \> /dev/null
91f08c3bdfSopenharmony_ci			EXPECT_PASS_BRK umount $mnt_point
92f08c3bdfSopenharmony_ci
93f08c3bdfSopenharmony_ci			tst_res TPASS "mount/umount with \"$mount_opt\" options"
94f08c3bdfSopenharmony_ci		done
95f08c3bdfSopenharmony_ci	done
96f08c3bdfSopenharmony_ci}
97f08c3bdfSopenharmony_ci
98f08c3bdfSopenharmony_ci. tst_test.sh
99f08c3bdfSopenharmony_citst_run
100