MNTOPTS(3)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 15.1

πŸ’… 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 β€” tells getmntopts() that the name has the inverse meaning of the bit. like, "suid" is the string, whereas the mount flag is MNT_NOSUID. the sense of the string and the flag are inverted, so the m_inverse flag 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 the m_inverse flag causes these two operations to be reversed. lowkey chaotic but we love her.
  • m_altloc β€” the bit should be set or cleared in altflagp rather than flagp.

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 the getmntpoint() function or the getmntinfo(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 to build_iovec(), iov should be set to NULL and iovlen should be set to 0. 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 to build_iovec_argf(), iov should be set to NULL and iovlen should be set to 0.

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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms