Bug 265200 - du -at broken – filters out only directories, not all files
Summary: du -at broken – filters out only directories, not all files
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-07-13 20:07 UTC by наб
Modified: 2025-04-28 18:21 UTC (History)
6 users (show)

See Also:


Attachments
Add threshold check to regular files, patch for file /usr/src/usr.bin/du/du.c (489 bytes, patch)
2024-01-17 06:45 UTC, Michal Scigocki
no flags Details | Diff
Add du -t test, patch for file /usr/src/usr.bin/du/tests/du_test.sh (953 bytes, patch)
2024-01-17 06:48 UTC, Michal Scigocki
no flags Details | Diff
Add du -t test, patch for file /usr/src/usr.bin/du/tests/du_test.sh (985 bytes, patch)
2025-02-28 13:41 UTC, Mark Linimon
no flags Details | Diff
Add threshold check to regular files, patch for file /usr/src/usr.bin/du/du.c (511 bytes, patch)
2025-02-28 13:43 UTC, Mark Linimon
no flags Details | Diff
Add du -t test, patch for file /usr/src/usr.bin/du/tests/du_test.sh (985 bytes, patch)
2025-02-28 13:46 UTC, Mark Linimon
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description наб 2022-07-13 20:07:12 UTC
Consider the following:

root@freebsd:/bin # du -h -d1 -t 200000000 /usr
275M    /usr/bin
992M    /usr/lib
478M    /usr/local
296M    /usr/lib32
2.2G    /usr
root@freebsd:/bin # du -h -d1 -t -200000000 /usr
 27M    /usr/include
 40K    /usr/libdata
3.6M    /usr/libexec
 19M    /usr/sbin
110M    /usr/share
 96M    /usr/tests
144K    /usr/home

This is correct.

However:
root@freebsd:/bin # du -aht 20000000
 16K    ./cat
 12K    ./chflags
 20K    ./chio
 12K    ./chmod
 24K    ./cp
 24K    ./date
 32K    ./dd
 16K    ./df
8.0K    ./domainname
8.0K    ./echo
 52K    ./ed
 24K    ./expr
4.0K    ./freebsd-version
 12K    ./getfacl
8.0K    ./hostname
8.0K    ./kenv
 12K    ./kill
 12K    ./ln
 36K    ./ls
8.0K    ./mkdir
 16K    ./mv
104K    ./pax
 20K    ./pkill
 48K    ./ps
 12K    ./pwait
8.0K    ./pwd
8.0K    ./realpath
 16K    ./rm
8.0K    ./rmdir
 24K    ./setfacl
160K    ./sh
8.0K    ./sleep
 24K    ./stty
8.0K    ./sync
 16K    ./test
 12K    ./uuidgen
 76K    ./rmail
448K    ./csh
  0B    ./ksh
root@freebsd:/bin # du -aht -20000000
 16K    ./cat
 12K    ./chflags
 20K    ./chio
 12K    ./chmod
 24K    ./cp
 24K    ./date
 32K    ./dd
 16K    ./df
8.0K    ./domainname
8.0K    ./echo
 52K    ./ed
 24K    ./expr
4.0K    ./freebsd-version
 12K    ./getfacl
8.0K    ./hostname
8.0K    ./kenv
 12K    ./kill
 12K    ./ln
 36K    ./ls
8.0K    ./mkdir
 16K    ./mv
104K    ./pax
 20K    ./pkill
 48K    ./ps
 12K    ./pwait
8.0K    ./pwd
8.0K    ./realpath
 16K    ./rm
8.0K    ./rmdir
 24K    ./setfacl
160K    ./sh
8.0K    ./sleep
 24K    ./stty
8.0K    ./sync
 16K    ./test
 12K    ./uuidgen
 76K    ./rmail
448K    ./csh
  0B    ./ksh
1.3M    .

I'd expect at least one of these to produce 0 output, but both of them output everything.

du(1) says:
     -t threshold
             Display only entries for which size exceeds threshold.  If
             threshold is negative, display only entries for which size is
             less than the absolute value of threshold.
explicitly mentioning "entries", not just directories (coreutils du, where -t originates, handles this as expected).
Comment 1 Mark Linimon freebsd_committer freebsd_triage 2024-01-10 04:44:27 UTC
^Triage: this does not seem to be actively in progress.
Comment 2 Michal Scigocki 2024-01-17 06:45:22 UTC
Created attachment 247720 [details]
Add threshold check to regular files, patch for file /usr/src/usr.bin/du/du.c
Comment 3 Michal Scigocki 2024-01-17 06:48:32 UTC
Created attachment 247722 [details]
Add du -t test, patch for file /usr/src/usr.bin/du/tests/du_test.sh
Comment 4 Michal Scigocki 2024-01-17 07:06:25 UTC
Hello,

I had a look, and the original implementation of the du threshold was only checking the threshold for directory type files. The threshold wasn't being checked for regular files, i.e. when the -a flag was set.

I have created a patch that applies the same threshold check also for regular files.

I also created a patch that adds a test for the du -t behaviour.

I checked the patch and ran the du kyua test on 14.0-RELEASE and 15.0-CURRENT.
Comment 5 Mark Linimon freebsd_committer freebsd_triage 2025-02-28 13:41:36 UTC
Created attachment 258064 [details]
Add du -t test, patch for file /usr/src/usr.bin/du/tests/du_test.sh

^Triage: rebase patch.
Comment 6 Mark Linimon freebsd_committer freebsd_triage 2025-02-28 13:43:40 UTC
Created attachment 258065 [details]
Add threshold check to regular files, patch for file /usr/src/usr.bin/du/du.c

^Triage: rebase patch.
Comment 7 Mark Linimon freebsd_committer freebsd_triage 2025-02-28 13:46:51 UTC
Created attachment 258066 [details]
Add du -t test, patch for file /usr/src/usr.bin/du/tests/du_test.sh

^Triage: rebase patch.
Comment 8 Michal Scigocki 2025-04-08 08:05:46 UTC
I added some more tests, rebased and updated the patch. I have made a pull request with the changes to github. https://github.com/freebsd/freebsd-src/pull/1648
Comment 9 commit-hook freebsd_committer freebsd_triage 2025-04-28 18:21:57 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=0ae2b9e866d3aea1e9141841488561f12603f879

commit 0ae2b9e866d3aea1e9141841488561f12603f879
Author:     Michal Scigocki <michal.os@hotmail.com>
AuthorDate: 2025-04-07 11:14:44 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2025-04-28 18:20:37 +0000

    du: Fix threshold on non-directory files

    PR:             265200
    Reviewed by:    markj
    MFC after:      1 month
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/1648

 usr.bin/du/du.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)