MNTOPTS(3)
π MNTOPTS(3) β the manual page bestie π
okay so this is MNTOPTS(3), a Library Functions Manual page, and it's literally the whole mount-point-ops friend group. no cap, these functions carry the entire vibe of getting a filesystem mounted. let's get into it π«Ά
β¨ NAME β¨
getmntopts, getmntpoint, chkdoreload, build_iovec, build_iovec_argf, free_iovec, checkpath, rmslashes β the mount point operations squad. that's the whole crew, all of them, periodt. π
π LIBRARY π
System Utilities Library (libutil, -lutil). so yeah, link with -lutil or you're gonna have a bad time. π
π¦ SYNOPSIS π¦
#include <mntopts.h>
void
getmntopts(const char *options, const struct mntopt *mopts, int *flagp,
int *altflagp);
struct statfs *
getmntpoint(const char *name);
int
chkdoreload(struct statfs *mntp, void (*prtmsg)(const char *fmt, ...));
void
build_iovec(struct iovec **iov, int *iovlen, const char *name,
void *val, size_t len);
void
build_iovec_argf(struct iovec **iov, int *iovlen, const char *name,
const char *fmt, ...);
void
free_iovec(struct iovec **iov, int *iovlen);
int
checkpath(const char *path, char *resolved);
void
rmslashes(char *rrpin, char *rrpout);
π DESCRIPTION π
the mntopts functions are the whole support system for operations that come with a mount point. like, the emotional backbone of mounting. π
πΈ getmntopts() β the option decoder πΈ
getmntopts() takes a comma separated option list and a list of valid option names, and computes the bitmask corresponding to the requested set of options. it's giving "glow-up for strings into bits" honestly.
so options gets broken down into a sequence of comma separated tokens. each token is looked up in the table described by mopts, and the bits in the word referenced by either flagp or altflagp (depending on the m_altloc field of the option's table entry) get updated. β
β οΈ heads up bestie: the flag words are not initialized by getmntopts(). you gotta do that yourself, okay? don't come crying to me.
the table, mopts, has this exact format:
struct mntopt {
char *m_option; /* option name */
int m_inverse; /* is this a negative option, e.g., "dev" */
int m_flag; /* bit to set, e.g., MNT_RDONLY */
int m_altloc; /* non-zero to use altflagp rather than flagp */
};
the members of this struct are:
m_optionβ the option name, for example"suid". iconic, short, to the point.m_inverseβ tellsgetmntopts()that the name has the inverse meaning of the bit. like,"suid"is the string, whereas the mount flag isMNT_NOSUID. the sense of the string and the flag are inverted, so them_inverseflag should be set. it's giving "opposites attract" vibes. πm_flagβ the value of the bit to be set or cleared in the flag word when the option is recognized. the bit is set when the option is discovered, but cleared if the option name was preceded by the letters"no". and them_inverseflag causes these two operations to be reversed. lowkey chaotic but we love her.m_altlocβ the bit should be set or cleared inaltflagprather thanflagp.
each of the user visible MNT_ flags has a corresponding MOPT_ macro which defines an appropriate struct mntopt entry. to simplify the program interface and ensure consistency across all programs, there's a general purpose macro, MOPT_STDOPTS, which contains an entry for all the generic VFS options. β¨
plus, the macros MOPT_FORCE and MOPT_UPDATE exist to enable the MNT_FORCE and MNT_UPDATE flags to be set. and finally β the table must be terminated by an entry with a NULL first element. do not forget the NULL terminator, it's the periodt of the table. π₯
π§ getmntpoint() β the mount point finder π§
getmntpoint() takes the pathname of a possible mount point or of a device (with or without /dev/ prepended to it). iykyk.
- if the pathname is a directory or a file,
getmntpoint()checks to see if the mount point currently has a filesystem mounted on it. - if the pathname is a device,
getmntpoint()checks to see if it is currently mounted.
if there's an associated mount, a pointer to a struct statfs is returned.
π caveat alert: the returned result is stored in a static buffer that is over-written each time thegetmntpoint()function or thegetmntinfo(3)library routine is called. so don't be storing that pointer thinking it's yours forever, bestie, it's not.
if no mount is found, NULL is returned. sad but true. π
π chkdoreload() β the read-only refresh π
chkdoreload() takes a pointer to a struct statfs. if the filesystem associated with the mount point is mounted read-only, chkdoreload() requests the filesystem to reload all of its metadata from its backing store. it's giving "factory reset but make it filesystem". π
the second parameter is the function to call to print an error message if the reload fails. if no error message is desired, a NULL can be passed as the second argument. chkdoreload() returns zero on success or non-zero on failure. slay. β
π build_iovec() β the parameter stacker π
build_iovec() adds a parameter to a list of parameters to be passed to the nmount(2) system call. the parameter list is built up in iov and its length is kept in iovlen.
π before the first call tobuild_iovec(),iovshould be set toNULLandiovlenshould be set to0. no exceptions, that's the ritual.
the parameter name is passed in name. the value of the parameter name is pointed to by val. the size of the value is passed in len. if the value is a string, a len of -1 is passed to indicate that the length should be determined using strlen(3). and if the parameter has no value, name should be NULL and len should be 0. π«Ά
π build_iovec_argf() β the formatted parameter stacker π
build_iovec_argf() adds a formatted parameter to a list of parameters to be passed to the nmount(2) system call. the parameter list is built up in iov and its length is kept in iovlen.
π same ritual as before: before the first call tobuild_iovec_argf(),iovshould be set toNULLandiovlenshould be set to0.
the parameter name is passed in name. the value of the parameter name is described by a format string pointed to by fmt. if the parameter has no value, name should be NULL. β¨
πΈ free_iovec() β the cleanup queen πΈ
free_iovec() frees the memory in the iov vector of the length specified in iovlen that was previously allocated by the build_iovec() and / or build_iovec_argf() functions. the iov is set to NULL and the iovlen is set to 0 to indicate that the space has been freed. she cleans up after herself, unlike some people. π
π¦ checkpath() β the directory validator π¦
checkpath() uses realpath(3) to verify that its path argument is valid and references a directory. returns zero on success or non-zero on failure. it's the vibe check for paths, honestly. β
β rmslashes() β the slash remover β
rmslashes() removes all double slashes and trailing slashes from its rrpin pathname parameter and returns the resulting pathname in its rrpout parameter. neat, tidy, iconic. π
π₯ EXAMPLES π₯
most commands will use the standard option set. local file systems which support the MNT_UPDATE flag would also have an MOPT_UPDATE entry. this can be declared and used as follows:
#include <mntopts.h>
struct mntopt mopts[] = {
MOPT_STDOPTS,
MOPT_UPDATE,
{ NULL }
};
...
mntflags = mntaltflags = 0;
...
getmntopts(options, mopts, &mntflags, &mntaltflags);
...
see that { NULL } at the end? that's the terminator. don't skip her. π
π DIAGNOSTICS π
if the external integer variable getmnt_silent is zero, then getmntopts() displays an error message and exits if an unrecognized option is encountered. otherwise, unrecognized options are silently ignored. by default getmnt_silent is zero. so yeah, default behavior is "loud and dramatic," which is honestly so on brand. π
π§ SEE ALSO π§
nmount(2), err(3), mount(8) β go read those too, bestie, they're all part of the lore. π«Ά
π HISTORY π
getmntopts() appeared in 4.4BSD. the build_iovec(), build_iovec_argf(), free_iovec(), checkpath(), and rmslashes() functions were added with nmount(2) in FreeBSD 5.0. the getmntpoint() and chkdoreload() functions were added in FreeBSD 13.2. glow-up timeline, honestly. β¨
historically, these functions were found in getmntopts.c in the source code of the mount(8) program. as of FreeBSD 15.0 they are part of libutil. moving out and getting their own place, we love to see it. π π
and that's the whole page, bestie!! this one came from the Debian edition of the manual, dated April 21, 2025 β go forth and mount responsibly π β¨π
π¦ where this page comes from
- freebsd 15.1: base 15.1
- Copyright (c) 2023 Marshall Kirk McKusick
- Copyright (c) 1994 The Regents of the University of California
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms