Add/fix copyright notices and adjust to latest GNU FDL.
[platform/upstream/coreutils.git] / tests / du / slink
1 #!/bin/sh
2 # Ensure that the size of a long-named-symlink is > 0.
3
4 # Copyright (C) 2002, 2003, 2004 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 2 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, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 # 02110-1301, USA.
20
21 if test "$VERBOSE" = yes; then
22   set -x
23   du --version
24 fi
25
26 pwd=`pwd`
27 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
28 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
29 trap '(exit $?); exit $?' 1 2 13 15
30
31 framework_failure=0
32 mkdir -p $tmp || framework_failure=1
33 cd $tmp || framework_failure=1
34
35 # Determine if `.' is on a local (would non-NFS be sufficient?) file system.
36 # On at least some NFS implementations, symlinks never take up space,
37 df --local . | tail -n +2 > tmp
38 # So if this is a non-local file system, skip the test.
39 if test -s tmp; then
40   : # Ok.
41 else
42   echo "$0: skipping this test, since \`.' is on a non-local file system" 1>&2
43   (exit 77); exit 77
44 fi
45
46 df --type=xfs . | tail -n +2 > tmp
47 if test -s tmp; then
48   # At least on Irix-6.5.19, when using an xfs file system,
49   # each created symlink (name lengths up to 255) would have a size of `0'.
50   echo "$0: skipping this test, since \`.' is on an XFS file system" 1>&2
51   (exit 77); exit 77
52 fi
53
54 if test $framework_failure = 1; then
55   echo "$0: failure in testing framework" 1>&2
56   (exit 1); exit 1
57 fi
58
59 fail=0
60 symlink_name_lengths='1 15 16 31 32 59 60 63 64 127 128 255 256 511 512 1024'
61 for len in $symlink_name_lengths; do
62   name=`seq 1 $len|tr -c x y |head -c$len`
63   # Record the names of symlinks that are successfully created.
64   ln -fs $name $len > /dev/null 2>&1 \
65     && symlinks="$symlinks $len"
66 done
67
68 du -a $symlinks > out || fail=1
69
70 # Require that at least one of these symlinks has a non-zero size.
71 grep '^[1-9]' out > /dev/null || fail=1
72
73 (exit $fail); exit $fail