Page MenuHomeFreeBSD

Fix getmntpoint(3) to operate as it is documented in its manual page.
ClosedPublic

Authored by mckusick on Oct 18 2025, 7:11 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Jan 21, 10:48 PM
Unknown Object (File)
Fri, Jan 16, 8:14 PM
Unknown Object (File)
Fri, Jan 16, 3:01 AM
Unknown Object (File)
Wed, Jan 14, 6:48 PM
Unknown Object (File)
Wed, Jan 14, 12:02 PM
Unknown Object (File)
Mon, Jan 12, 9:42 PM
Unknown Object (File)
Dec 26 2025, 2:54 PM
Unknown Object (File)
Dec 26 2025, 2:29 PM
Subscribers

Details

Summary

Dag-Erling Smørgrav <des@FreeBSD.org> reoprts:
While working on quot(8), I noticed that getmntpoint(3) does not actually accept a device name “with or without /dev/ prepended to it” as the manual page and code comments claim.

This patch corrects the problem by prepending /dev/ to names that do not begin with a '/'.

Since there are now two places in the code that want to prepend /dev/ the code to do this is broken out into a separate function.

Test Plan

Note that this fix cannot be tested with the df(1) command as it does not use getmntpoint(3).

This program can be used to test getmntpoit(3): {F132597285}

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

des requested changes to this revision.Oct 18 2025, 7:36 AM
des added inline comments.
lib/libutil/mntopts.c
151

Please use a caller-provided buffer instead

179

Missing a null check here

This revision now requires changes to proceed.Oct 18 2025, 7:36 AM
mckusick marked 2 inline comments as done.

Respond to Dag-Erling's comments.

Responding to Dag-Erling's comments.

lib/libutil/mntopts.c
151

It takes more parameters, more lines of code, and generally makes the code harder to follow. That said, I have made the change.

179

stat(NULL, &statbuf) returns -1 (EBADF) which will have the correct response here. It seems pointless to add an explicit test for NULL.

Add comment on why it is not necessary to check for NULL return from prependdevtopath().

lib/libutil/mntopts.c
151

agreed, but making getmntpoint() thread-unsafe is worse, imo

179

EBADF isn't a very useful errno value for our caller, though. I think it would be better to restore the errno value from the original stat(2) call if prependdevtopath() fails.

208

this else is unnecessary

mckusick marked an inline comment as done.

Get rid of unneeded else statement.

Respond to latest comments.

lib/libutil/mntopts.c
179

We make no claims about what systems calls we have done or what error they have returned. We simply return a pointer to a statfs structure or NULL. We do several systems calls to implement this routine all of which could fail for various reasons, No caller of this routine should make any use or interpretation of errno.

btw this can be tested with quot(8), e.g. quot md0.

This revision is now accepted and ready to land.Oct 22 2025, 1:03 PM