Skip to content

mountpoint: add -d/--fs-devno and -x/--devno - #726

Open
Harp404 wants to merge 1 commit into
uutils:mainfrom
Harp404:mountpoint-devno
Open

Harp404 wants to merge 1 commit into
uutils:mainfrom
Harp404:mountpoint-devno

Conversation

@Harp404

@Harp404 Harp404 commented Dec 1, 2026

Copy link
Copy Markdown

The usage line of mountpoint lists -d and -x, but neither was implemented:

$ mountpoint -d /
error: unexpected argument '-d' found

This adds them, following util-linux 2.41.3:

  • -d/--fs-devno PATH prints the major:minor device number of the filesystem mounted on PATH. Like util-linux, it is taken from the topmost (last) /proc/self/mountinfo entry for the path rather than from st_dev. The two differ for a bind-mounted file such as WSL's /mnt/wslg/versions.txt (0:42 in mountinfo, 0:44 from stat). Without /proc, it falls back to st_dev with the existing device check. A path that is not a mount point gives the usual message and exit status 32.
  • -x/--devno DEVICE prints the major:minor of a block device, and otherwise fails with PATH: not a block device and exit status 32. Like util-linux, -x wins when both are given.

On my machine, -d prints the same output and exit status as util-linux for all 37 mount points in mountinfo (including two stacked ones), and -x matches for /dev/sda, /dev/sdb, /, /dev/null and a missing path. major/minor come from libc, which is now a unix dependency of uu_mountpoint.

The 3 new tests in tests/by-util/test_mountpoint.rs fail on main and pass with this change. cargo fmt and cargo clippy --all-targets -- -D warnings are clean. This touches the same function as #725 (-q). Whichever is merged second will need a small rebase, which I'll do.

I used Claude Code (Opus 5.5) to help investigate and draft this change; I reproduced the bug and checked the fix myself.

Copilot AI balanced review requested due to automatic review settings December 1, 2026 09:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

/// topmost (last) mountinfo entry for the path, which can differ from the
/// path's `st_dev`, for example for a bind-mounted file.
#[cfg(target_os = "linux")]
fn fs_devno(path: &str) -> std::io::Result<Option<String>> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is almost the same code as is_mountpoint (mountinfo scan + by-device fallback)
could is_mountpoint just be fs_devno(path).map(|d| d.is_some()), no?

#[cfg(not(windows))]
fn format_devno(dev: u64) -> String {
// dev_t is narrower than u64 on some platforms, such as macOS
#[allow(clippy::unnecessary_cast)]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we avoid the #[allow]? e.g. libc::dev_t::try_from(dev) or take a libc::dev_t directly

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.

3 participants