Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/tools/testing/selftests/filesystems/fat/run_fat_tests.sh
26302 views
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 <[email protected]>
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
83
84