summaryrefslogtreecommitdiff
path: root/tests/ls
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ls')
-rwxr-xr-xtests/ls/stat-vs-dirent59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/ls/stat-vs-dirent b/tests/ls/stat-vs-dirent
new file mode 100755
index 000000000..2e0c0282d
--- /dev/null
+++ b/tests/ls/stat-vs-dirent
@@ -0,0 +1,59 @@
+#!/bin/sh
+# Ensure that d_ino (from ls -di) and st_ino (from stat --format=%i) match.
+
+if test "$VERBOSE" = yes; then
+ set -x
+ ls --version
+fi
+
+. $srcdir/../envvar-check
+
+pwd=`pwd`
+t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
+trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
+trap '(exit $?); exit $?' 1 2 13 15
+
+framework_failure=0
+mkdir -p $tmp || framework_failure=1
+cd $tmp || framework_failure=1
+
+if test $framework_failure = 1; then
+ echo "$0: failure in testing framework" 1>&2
+ (exit 1); exit 1
+fi
+
+fail=0
+
+root_dev_ino=`stat --format=%d-%i /`
+t=`pwd`
+while :; do
+ ls -i1 "$t" > tmp
+ if test $? = 0; then
+ # Extract the inode number from the first line of output from ls -i1.
+ # This value comes from dirent.d_ino, on systems with d_ino support.
+ d_ino=`sed -n '1s/^ *\([0-9][0-9]*\) .*/\1/p;q' tmp`
+
+ # Extract the name of the corresponding directory entry.
+ file=`sed -n '1s/^ *[0-9][0-9]* *//p;q' tmp`
+
+ # Get its inode number (stat.st_ino) via stat(1)'s call to lstat.
+ st_ino=`stat --format=%i "$t/$file"`
+
+ # Make sure that they are the same.
+ # We know from experience that there may be mismatches on some
+ # buggy file systems, at mount points.
+ if test "$d_ino" != "$st_ino"; then
+ echo "$0: test failed: $t/$file: d_ino($d_ino) != st_ino($st_ino)" 1>&2
+ echo "$0: This may indicate a flaw in your kernel or" \
+ "file system implementation." 1>&2
+ fail=1
+ break
+ fi
+ fi
+
+ t=`(cd "$t/.."; pwd)`
+ dev_ino=`stat --format=%d-%i "$t"`
+ test $dev_ino = $root_dev_ino && break
+done
+
+(exit $fail); exit $fail