* gnulib: Update submodule to latest.
[coreutils.git] / tests / ls / stat-vs-dirent
blob2c3b064db3b8a3a5278ff17fc4aa01799a368f2c
1 #!/bin/sh
2 # Ensure that d_ino (from ls -di) and st_ino (from stat --format=%i) match.
4 # Copyright (C) 2006-2008 Free Software Foundation, Inc.
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.
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.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 if test "$VERBOSE" = yes; then
20 set -x
21 ls --version
24 . $srcdir/test-lib.sh
26 fail=0
28 root_dev_ino=`stat --format=%d-%i /`
29 t=`pwd`
30 while :; do
31 ls -i1 "$t" > tmp
32 if test $? = 0; then
33 # Extract the inode number from the first line of output from ls -i1.
34 # This value comes from dirent.d_ino, on systems with d_ino support.
35 d_ino=`sed -n '1s/^ *\([0-9][0-9]*\) .*/\1/p;q' tmp`
37 # Extract the name of the corresponding directory entry.
38 file=`sed -n '1s/^ *[0-9][0-9]* *//p;q' tmp`
40 # Get its inode number (stat.st_ino) via stat(1)'s call to lstat.
41 st_ino=`stat --format=%i "$t/$file"`
43 # Make sure that they are the same.
44 # We know from experience that there may be mismatches on some
45 # buggy file systems, at mount points.
46 if test "$d_ino" != "$st_ino"; then
47 echo "$0: test failed: $t/$file: d_ino($d_ino) != st_ino($st_ino)
48 This may indicate a flaw in your kernel or file system implementation.
49 The flaw isn't serious for coreutils, but it might break other tools,
50 so you should report it to your operating system vendor." 1>&2
52 # This test fails too often, and we don't want to be distracted
53 # with reports, since the code that could be affected by the losing
54 # behavior (pwd and getcwd) works around any mismatch.
55 # So do continue to issue the warning, but don't count it as a
56 # real failure.
57 # fail=1
58 break
62 t=`(cd "$t/.."; pwd)`
63 dev_ino=`stat --format=%d-%i "$t"`
64 test $dev_ino = $root_dev_ino && break
65 done
67 Exit $fail