rm: remove no-op -d option
[coreutils.git] / tests / ls / stat-vs-dirent
blob25b2021e13e1724cfc88e9482b0b65073865e694
1 #!/bin/sh
2 # Ensure that d_ino (from ls -di) and st_ino (from stat --format=%i) match.
4 # Copyright (C) 2006-2010 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
27 root_dev_ino=`stat --format=%d-%i /`
28 t=`pwd`
29 while :; do
30 ls -i1 "$t" > tmp
31 if test $? = 0; then
32 # Extract the inode number from the first line of output from ls -i1.
33 # This value comes from dirent.d_ino, on systems with d_ino support.
34 d_ino=`sed -n '1s/^ *\([0-9][0-9]*\) .*/\1/p;q' tmp`
36 # Extract the name of the corresponding directory entry.
37 file=`sed -n '1s/^ *[0-9][0-9]* *//p;q' tmp`
39 # Get its inode number (stat.st_ino) via stat(1)'s call to lstat.
40 st_ino=`stat --format=%i "$t/$file"`
42 # Make sure that they are the same.
43 # We know from experience that there may be mismatches on some
44 # buggy file systems, at mount points.
45 # Note that when a directory contains only entries whose names
46 # start with ".", d_ino and file will both be empty. In that case,
47 # skip the test.
48 if test -n "$d_ino" && test "$d_ino" != "$st_ino"; then
49 echo "$0: test failed: $t/$file: d_ino($d_ino) != st_ino($st_ino)
50 This may indicate a flaw in your kernel or file system implementation.
51 The flaw isn't serious for coreutils, but it might break other tools,
52 so you should report it to your operating system vendor." 1>&2
54 fail=1
55 break
59 t=`(cd "$t/.."; pwd)`
60 dev_ino=`stat --format=%d-%i "$t"`
61 test $dev_ino = $root_dev_ino && break
62 done
64 Exit $fail