Problem reported by Christoph Anton Mitterer (Bug#61884).
* src/du.c (process_file): When counting apparent sizes, count
only usable st_size members.
* tests/du/apparent.sh: New file.
* tests/local.mk (all_root_tests): Add it.
to support unusual devices that may have this constraint.
[behavior inadvertently changed in coreutils-7.2]
+ du --apparent now counts apparent sizes only of regular files and
+ symbolic links. POSIX does not specify the meaning of apparent
+ sizes (i.e., st_size) for other file types, and counting those sizes
+ could cause confusing and unwanted size mismatches.
+
'ls -v' and 'sort -V' go back to sorting ".0" before ".A",
reverting to the behavior in coreutils-9.0 and earlier.
This behavior is now documented.
has an apparent size of 2 GiB, yet on most modern
file systems, it actually uses almost no space.
+Apparent sizes are meaningful only for regular files and symbolic links.
+Other file types do not contribute to apparent size.
+
@item -B @var{size}
@itemx --block-size=@var{size}
@opindex -B
static bool opt_all = false;
/* If true, rather than using the device usage of each file,
- use the apparent size (a la stat.st_size). */
+ use the apparent size (stat.st_size if usable, 0 otherwise). */
static bool apparent_size = false;
/* If true, count each hard link of files with multiple links. */
size_t level;
static size_t n_alloc;
/* First element of the structure contains:
- The sum of the st_size values of all entries in the single directory
- at the corresponding level. Although this does include the st_size
+ The sum of the sizes of all entries in the single directory
+ at the corresponding level. Although this does include the sizes
corresponding to each subdirectory, it does not include the size of
any file in a subdirectory. Also corresponding last modified date.
Second element of the structure contains:
duinfo_set (&dui,
(apparent_size
- ? MAX (0, sb->st_size)
+ ? (usable_st_size (sb) ? MAX (0, sb->st_size) : 0)
: (uintmax_t) ST_NBLOCKS (*sb) * ST_NBLOCKSIZE),
(time_type == time_mtime ? get_stat_mtime (sb)
: time_type == time_atime ? get_stat_atime (sb)
--- /dev/null
+#!/bin/sh
+# Exercise du's --apparent-size option.
+
+# Copyright 2023 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ du
+
+mkdir -p d || framework_failure_
+for f in $(seq 100); do
+ echo foo >d/$f || framework_failure_
+done
+
+du -b d/* >separate || fail=1
+du -b d >together || fail=1
+separate_sum=$($AWK '{sum+=$1}END{print sum}' separate) || framework_failure_
+together_sum=$($AWK '{sum+=$1}END{print sum}' together) || framework_failure_
+test $separate_sum -eq $together_sum || fail=1
+
+Exit $fail
tests/dd/skip-seek-past-dev.sh \
tests/df/problematic-chars.sh \
tests/df/over-mount-device.sh \
+ tests/du/apparent.sh \
tests/du/bind-mount-dir-cycle.sh \
tests/du/bind-mount-dir-cycle-v2.sh \
tests/id/setgid.sh \