~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/filesystems/fat/run_fat_tests.sh

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/bash
  2 # SPDX-License-Identifier: GPL-2.0
  3 #
  4 # Run filesystem operations tests on an 1 MiB disk image that is formatted with
  5 # a vfat filesystem and mounted in a temporary directory using a loop device.
  6 #
  7 # Copyright 2022 Red Hat Inc.
  8 # Author: Javier Martinez Canillas <javierm@redhat.com>
  9 
 10 set -e
 11 set -u
 12 set -o pipefail
 13 
 14 BASE_DIR="$(dirname $0)"
 15 TMP_DIR="$(mktemp -d /tmp/fat_tests_tmp.XXXXXX)"
 16 IMG_PATH="${TMP_DIR}/fat.img"
 17 MNT_PATH="${TMP_DIR}/mnt"
 18 
 19 cleanup()
 20 {
 21     mountpoint -q "${MNT_PATH}" && unmount_image
 22     rm -rf "${TMP_DIR}"
 23 }
 24 trap cleanup SIGINT SIGTERM EXIT
 25 
 26 create_loopback()
 27 {
 28     touch "${IMG_PATH}"
 29     chattr +C "${IMG_PATH}" >/dev/null 2>&1 || true
 30 
 31     truncate -s 1M "${IMG_PATH}"
 32     mkfs.vfat "${IMG_PATH}" >/dev/null 2>&1
 33 }
 34 
 35 mount_image()
 36 {
 37     mkdir -p "${MNT_PATH}"
 38     sudo mount -o loop "${IMG_PATH}" "${MNT_PATH}"
 39 }
 40 
 41 rename_exchange_test()
 42 {
 43     local rename_exchange="${BASE_DIR}/rename_exchange"
 44     local old_path="${MNT_PATH}/old_file"
 45     local new_path="${MNT_PATH}/new_file"
 46 
 47     echo old | sudo tee "${old_path}" >/dev/null 2>&1
 48     echo new | sudo tee "${new_path}" >/dev/null 2>&1
 49     sudo "${rename_exchange}" "${old_path}" "${new_path}" >/dev/null 2>&1
 50     sudo sync -f "${MNT_PATH}"
 51     grep new "${old_path}" >/dev/null 2>&1
 52     grep old "${new_path}" >/dev/null 2>&1
 53 }
 54 
 55 rename_exchange_subdir_test()
 56 {
 57     local rename_exchange="${BASE_DIR}/rename_exchange"
 58     local dir_path="${MNT_PATH}/subdir"
 59     local old_path="${MNT_PATH}/old_file"
 60     local new_path="${dir_path}/new_file"
 61 
 62     sudo mkdir -p "${dir_path}"
 63     echo old | sudo tee "${old_path}" >/dev/null 2>&1
 64     echo new | sudo tee "${new_path}" >/dev/null 2>&1
 65     sudo "${rename_exchange}" "${old_path}" "${new_path}" >/dev/null 2>&1
 66     sudo sync -f "${MNT_PATH}"
 67     grep new "${old_path}" >/dev/null 2>&1
 68     grep old "${new_path}" >/dev/null 2>&1
 69 }
 70 
 71 unmount_image()
 72 {
 73     sudo umount "${MNT_PATH}" &> /dev/null
 74 }
 75 
 76 create_loopback
 77 mount_image
 78 rename_exchange_test
 79 rename_exchange_subdir_test
 80 unmount_image
 81 
 82 exit 0

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php