Path: blob/master/tools/testing/selftests/filesystems/fat/run_fat_tests.sh
26302 views
#!/bin/bash1# SPDX-License-Identifier: GPL-2.02#3# Run filesystem operations tests on an 1 MiB disk image that is formatted with4# a vfat filesystem and mounted in a temporary directory using a loop device.5#6# Copyright 2022 Red Hat Inc.7# Author: Javier Martinez Canillas <[email protected]>89set -e10set -u11set -o pipefail1213BASE_DIR="$(dirname $0)"14TMP_DIR="$(mktemp -d /tmp/fat_tests_tmp.XXXXXX)"15IMG_PATH="${TMP_DIR}/fat.img"16MNT_PATH="${TMP_DIR}/mnt"1718cleanup()19{20mountpoint -q "${MNT_PATH}" && unmount_image21rm -rf "${TMP_DIR}"22}23trap cleanup SIGINT SIGTERM EXIT2425create_loopback()26{27touch "${IMG_PATH}"28chattr +C "${IMG_PATH}" >/dev/null 2>&1 || true2930truncate -s 1M "${IMG_PATH}"31mkfs.vfat "${IMG_PATH}" >/dev/null 2>&132}3334mount_image()35{36mkdir -p "${MNT_PATH}"37sudo mount -o loop "${IMG_PATH}" "${MNT_PATH}"38}3940rename_exchange_test()41{42local rename_exchange="${BASE_DIR}/rename_exchange"43local old_path="${MNT_PATH}/old_file"44local new_path="${MNT_PATH}/new_file"4546echo old | sudo tee "${old_path}" >/dev/null 2>&147echo new | sudo tee "${new_path}" >/dev/null 2>&148sudo "${rename_exchange}" "${old_path}" "${new_path}" >/dev/null 2>&149sudo sync -f "${MNT_PATH}"50grep new "${old_path}" >/dev/null 2>&151grep old "${new_path}" >/dev/null 2>&152}5354rename_exchange_subdir_test()55{56local rename_exchange="${BASE_DIR}/rename_exchange"57local dir_path="${MNT_PATH}/subdir"58local old_path="${MNT_PATH}/old_file"59local new_path="${dir_path}/new_file"6061sudo mkdir -p "${dir_path}"62echo old | sudo tee "${old_path}" >/dev/null 2>&163echo new | sudo tee "${new_path}" >/dev/null 2>&164sudo "${rename_exchange}" "${old_path}" "${new_path}" >/dev/null 2>&165sudo sync -f "${MNT_PATH}"66grep new "${old_path}" >/dev/null 2>&167grep old "${new_path}" >/dev/null 2>&168}6970unmount_image()71{72sudo umount "${MNT_PATH}" &> /dev/null73}7475create_loopback76mount_image77rename_exchange_test78rename_exchange_subdir_test79unmount_image8081exit 0828384