1#!/bin/sh
2# Ensure that df outputs one line per entry
3
4# Copyright (C) 2012-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 printf
21require_root_
22
23
24# Ensure a new line in a mount point only outputs a single line
25
26mnt='mount
27point'
28
29cwd=$(pwd)
30cleanup_() { umount "$cwd/$mnt"; }
31
32skip=0
33# Create a file system, then mount it.
34dd if=/dev/zero of=blob bs=8192 count=200 > /dev/null 2>&1 \
35                                             || skip=1
36mkdir "$mnt"                                 || skip=1
37mkfs -t ext2 -F blob \
38  || skip_ "failed to create ext2 file system"
39mount -oloop blob "$mnt"                     || skip=1
40test $skip = 1 \
41  && skip_ "insufficient mount/ext2 support"
42test $(df "$mnt" | wc -l) = 2 || fail=1
43test "$fail" = 1 && dump_mount_list_
44
45
46# Ensure mount points not matching the current user encoding are output
47
48unset LC_ALL
49f=$LOCALE_FR_UTF8
50: ${LOCALE_FR_UTF8=none}
51if test "$LOCALE_FR_UTF8" != "none"; then
52
53  cleanup_ || framework_failure_
54
55  # Create a non UTF8 mount point
56  mnt="$(env printf 'm\xf3unt p\xf3int')"
57  mkdir "$mnt" || framework_failure_
58  mount -oloop blob "$mnt" || skip_ "unable to mount $mnt"
59
60  LC_ALL=$f df --output=target "$mnt" > df.out || fail=1
61  test "$(basename "$(tail -n1 df.out)")" = "$mnt" || fail=1
62fi
63
64
65Exit $fail
66