Skip to content

Count bind mounts and repeated mounts once - #36

Merged
tobi merged 1 commit into
tobi:mainfrom
btsouth:bind-mounts-once
Sep 27, 2026
Merged

tobi merged 1 commit into
tobi:mainfrom
btsouth:bind-mounts-once

Conversation

@btsouth

@btsouth btsouth commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

A bind mount inside the scanned folder gets walked like extra data, so its files count twice. The same happens with a second mount of a disk that's already inside the scan (/data and /mnt/data, say), or the top of a Btrfs filesystem mounted next to its subvolumes. Device numbers can't catch these because a bind mount has its source's device, and /proc/self/mounts doesn't say which directory a mount shows. /proc/self/mountinfo does.

This reads mountinfo and leaves out the extra view when the same directory would be reached twice. The view showing the widest part of the filesystem is kept, so subvolumes like /home are scanned as before. The scanned root itself is never skipped. Without mountinfo (macOS, Windows) nothing changes.

To reproduce on main without root:

unshare -rm sh -c 'mkdir -p /tmp/b && mount -t tmpfs tmpfs /tmp/b &&
  mkdir /tmp/b/real /tmp/b/view && head -c 1000000 /dev/zero > /tmp/b/real/blob &&
  mount --bind /tmp/b/real /tmp/b/view && disktree /tmp/b'

Main counts the file twice; this branch counts it once.

Tests: unit tests for an Omarchy-style table (subvolumes are not repeats, a second mount of the data disk is), a bind of a subfolder, the Btrfs top level, and mountinfo's octal escapes. I also checked real bind mounts in a user namespace, and a scan of / on a machine without repeated mounts gives the same total as main. cargo xtask lint and cargo xtask test pass.

@tobi
tobi merged commit f3f37c2 into tobi:main Sep 27, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants