summaryrefslogtreecommitdiff
path: root/tests/find/inode-zero.sh
blob: 7bfc26982fadada560bc3dc4f5765f29286f779c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh
# Ensure find(1) treats inode number 0 correctly.

# Copyright (C) 2021 Free Software Foundation, Inc.

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

. "${srcdir=.}/tests/init.sh"; fu_path_prepend_
print_ver_ find

# Skip test unless we find a file with inode number 0.
# GNU/Hurd uses inode 0 for /dev/console.
f='/dev/console'
test -e "${f}" \
  && ino=$( stat -c '%i' "${f}" ) \
  && test "${ino}" = '0' \
  || skip_ "no file with inode number 0 here"

echo "${f}" > exp || framework_failure_

# Ensure -inum works.
# Find by exact inode number 0.
find "${f}" -inum 0 >out 2>err || fail=1
compare exp out || fail=1
compare /dev/null err || fail=1

# Find by inode number <1.
find "${f}" -inum -1 >out 2>err || fail=1
compare exp out || fail=1
compare /dev/null err || fail=1

# No match with unrelated inode number.
find "${f}" -inum 12345 >out 2>err || fail=1
compare /dev/null out || fail=1
compare /dev/null err || fail=1

# Ensure '-printf "%i"' works.
echo 0 > exp || framework_failure_
find "${f}" -printf '%i\n' >out 2>err || fail=1
compare exp out || fail=1
compare /dev/null err || fail=1

Exit $fail