2 # Ensure that du can handle a 2GB file (i.e., a file of size 2^31 bytes)
3 # Before coreutils-5.93, on systems with a signed, 32-bit stat.st_blocks
4 # one of du's computations would overflow.
6 # Copyright (C) 2005, 2006 Free Software Foundation, Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 if test "$VERBOSE" = yes; then
28 . $srcdir/../envvar-check
30 # Creating a 2GB file counts as `very expensive'.
31 . $srcdir/../very-expensive
34 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
35 trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0
36 trap '(exit $?); exit $?' 1 2 13 15
39 mkdir -p $tmp || framework_failure=1
40 cd $tmp || framework_failure=1
42 if test $framework_failure = 1; then
43 echo "$0: failure in testing framework" 1>&2
49 # Get number of free kilobytes on current partition, so we can
50 # skip this test if there is insufficient free space.
52 # This technique relies on the fact that the `Available' kilobyte
53 # count is the number just before the one with a trailing `%'.
54 free_kb=`df -kP .|tail -1|sed 's/ [0-9][0-9]*%.*//;s/ *$//;s/.* //'`
57 *) echo "invalid size from df: $free_kb" 1>&2; (exit 77); exit 77;;
60 # Require about 3GB free.
62 test $min_kb -lt $free_kb ||
64 echo "$0: skipping this test:"
65 echo "too little free space on current partition: $free_kb (need $min_kb KB)" \
72 test -t 1 || printf 'creating a 2GB file...\n'
73 for i in `seq 100`; do
74 # Note: 2147483648 == 2^31. Print floor(2^31/100) per iteration.
75 printf %21474836s x >> $big || fail=1
76 # On the final iteration, append the remaining 48 bytes.
77 test $i = 100 && { printf %48s x >> $big || fail=1; }
78 test -t 1 && printf 'creating a 2GB file: %d%% complete\r' $i
82 du -k $big > out1 || fail=1
84 sed 's/^2[0-9][0-9][0-9][0-9][0-9][0-9] '$big'$/~2M/' out1 > out
86 cat <<\EOF > exp || fail=1
91 test $fail = 1 && diff out exp 2> /dev/null
93 (exit $fail); exit $fail