1#!/bin/sh
2# Test df's behavior for skipping the pseudo "rootfs" file system.
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
21
22# Protect against inaccessible remote mounts etc.
23timeout 10 df || skip_ "df fails"
24
25# Verify that rootfs is in mtab (and shown when the -a option is specified).
26# Note this is the case when /proc/self/mountinfo is parsed
27# rather than /proc/mounts.  I.e., when libmount is being used.
28df -a >out || fail=1
29grep '^rootfs' out || skip_ 'no rootfs in mtab'
30
31# Ensure that rootfs is suppressed when no options is specified.
32df >out || fail=1
33grep '^rootfs' out && { fail=1; cat out; }
34
35# Ensure that rootfs is yet skipped when explicitly specifying "-t rootfs".
36# As df emits "no file systems processed" in this case, it would be a failure
37# if df exited with status Zero.
38returns_ 1 df -t rootfs >out || fail=1
39grep '^rootfs' out && { fail=1; cat out; }
40
41# Ensure that the rootfs is shown when explicitly both specifying "-t rootfs"
42# and the -a option.
43df -t rootfs -a >out || fail=1
44grep '^rootfs' out || { fail=1; cat out; }
45
46# Ensure that the rootfs is omitted in all_fs mode when it is explicitly
47# black-listed.
48df -a -x rootfs >out || fail=1
49grep '^rootfs' out && { fail=1; cat out; }
50
51test "$fail" = 1 && dump_mount_list_
52
53Exit $fail
54