1#!/bin/sh 2# Ensure that df /dev/loop0 errors out if overmounted by another device 3 4# Copyright (C) 2014-2023 Free Software Foundation, Inc. 5 6# This program is free software: you can redistribute it and/or modify 7# it under the terms of the GNU General Public License as published by 8# the Free Software Foundation, either version 3 of the License, or 9# (at your option) any later version. 10 11# This program is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15 16# You should have received a copy of the GNU General Public License 17# along with this program. If not, see <https://www.gnu.org/licenses/>. 18 19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src 20print_ver_ df 21require_root_ 22 23cwd=$(pwd) 24cleanup_() { cd /; umount "$cwd/mnt"; umount "$cwd/mnt"; } 25 26skip=0 27 28# Create 2 file systems 29for i in 1 2; do 30 dd if=/dev/zero of=blob$i bs=8192 count=200 > /dev/null 2>&1 \ 31 || skip=1 32 mkfs -t ext2 -F blob$i \ 33 || skip_ "failed to create ext2 file system" 34done 35 36# Mount both at the same place (eclipsing the first) 37mkdir mnt || skip=1 38mount -oloop blob1 mnt || skip=1 39eclipsed_dev=$(df --o=source mnt | tail -n1) || skip=1 40mount -oloop blob2 mnt || skip=1 41 42test $skip = 1 \ 43 && skip_ "insufficient mount/ext2 support" 44 45df . || skip_ "failed to lookup the device for the current dir" 46 47echo "df: cannot access '$eclipsed_dev': over-mounted by another device" > exp 48 49# We should get an error for the eclipsed device and continue 50df $eclipsed_dev . > out 2> err && fail=1 51 52# header and single entry in output 53test $(wc -l < out) = 2 || fail=1 54 55compare exp err || fail=1 56 57test "$fail" = 1 && dump_mount_list_ 58 59Exit $fail 60