summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLukáš Zaoral <lzaoral@redhat.com>2026-04-14 14:09:02 +0200
committerPádraig Brady <P@draigBrady.com>2026-04-15 12:56:16 +0100
commitf6fda635bdc8ea7b6665fa25f7ccc78484a47679 (patch)
tree38280f14fb3d0d383fcbb7350bf7d59e6921f948 /src
parent5cb0cca3b863e7aa5978f725c227c323a4a0d58f (diff)
downloadcoreutils-f6fda635bdc8ea7b6665fa25f7ccc78484a47679.tar.gz
coreutils-f6fda635bdc8ea7b6665fa25f7ccc78484a47679.zip
df: improve detection of duplicate entries
Do not compare only with the latest entry for given device id but also all previously saved entries with the same id. * src/df.c (struct devlist): Add next_same_dev struct member. (filter_mount_list): Iterate over next_same_dev to find duplicates. * tests/df/skip-duplicates.sh: Add test cases. * NEWS: Mention the improvement. https://redhat.atlassian.net/browse/RHEL-5649
Diffstat (limited to 'src')
-rw-r--r--src/df.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/df.c b/src/df.c
index 377b59dce..f41ba3a87 100644
--- a/src/df.c
+++ b/src/df.c
@@ -50,6 +50,7 @@ struct devlist
dev_t dev_num;
struct mount_entry *me;
struct devlist *next;
+ struct devlist *next_same_dev;
struct devlist *seen_last; /* valid for hashed devlist entries only */
};
@@ -720,6 +721,7 @@ filter_mount_list (bool devices_only)
{
struct stat buf;
struct mount_entry *discard_me = NULL;
+ struct devlist *last_seen_dev = NULL, *seen_dev = NULL;
/* Avoid stating remote file systems as that may hang.
On Linux we probably have me_dev populated from /proc/self/mountinfo,
@@ -737,9 +739,9 @@ filter_mount_list (bool devices_only)
else
{
/* If we've already seen this device... */
- struct devlist *seen_dev = devlist_for_dev (buf.st_dev);
+ last_seen_dev = seen_dev = devlist_for_dev (buf.st_dev);
- if (seen_dev)
+ for (; seen_dev && ! discard_me; seen_dev = seen_dev->next_same_dev)
{
bool target_nearer_root = strlen (seen_dev->me->me_mountdir)
> strlen (me->me_mountdir);
@@ -796,6 +798,7 @@ filter_mount_list (bool devices_only)
struct devlist *devlist = xmalloc (sizeof *devlist);
devlist->me = me;
devlist->dev_num = buf.st_dev;
+ devlist->next_same_dev = last_seen_dev;
devlist->next = device_list;
device_list = devlist;