KERNEL_MOUNT(9)

πŸ’– KERNEL_MOUNT(9) β€” the kernel dev manual, but make it cute πŸ’–

okay bestie, so this is the page for KERNEL_MOUNT(9) β€” it lives in the Kernel Developer's Manual, and it's literally the whole ~vibe~ of how you build mount arguments from inside the kernel. no cap. πŸŽ€


✨ NAME ✨

free_mntarg, kernel_mount, kernel_vmount, mount_arg, mount_argb, mount_argf, mount_argsu β€” functions provided as part of the kernel mount interface 🫢


🌸 SYNOPSIS 🌸

void
free_mntarg(struct mntarg *ma);

int
kernel_mount(struct mntarg *ma, int flags);

int
kernel_vmount(int flags, ...);

struct mntarg *
mount_arg(struct mntarg *ma, const char *name, const void *val,
    int len);

struct mntarg *
mount_argb(struct mntarg *ma, int flag, const char *name);

struct mntarg *
mount_argf(struct mntarg *ma, const char *name, const char *fmt, ...);

struct mntarg *
mount_argsu(struct mntarg *ma, const char *name, const void *val,
    int len);

πŸ’… DESCRIPTION πŸ’…

so the kernel_mount() family is the API you get handed when you wanna build up a lil list of mount arguments and then mount file systems from inside the kernel, bestie. that's the whole thing. it's giving "let me assemble a to-do list for the kernel". by accumulating a list of arguments, the API takes shape and hands over the info the kernel needs to control the mount(8) utility. iconic behavior honestly. 🧚

and like β€” when an error occurs, the process will stop. it will not cause a panic(9). so breathe. πŸ’€

the header of the structure is stored in src/sys/kern/vfs_mount.c, which permits automatic structure creation so the mount process is easier. memory allocation must always be freed when the entire process is complete β€” it is an error otherwise. yes, always. i don't make the rules (i do not make the rules). 😭

  • free_mntarg() β€” frees or clears the mntarg structure. bye bestie πŸ’–
  • kernel_mount() β€” pulls information from the structure to perform the mount request on a given file system. and plot twist: it always calls the free_mntarg() function too. if ma contains any error code generated during the construction, that code will be called and the file system mount will not be attempted. slay at cleaning up after itself fr fr.
  • kernel_vmount() β€” a function similar to printf(9), used to mount a file system. ✨
  • mount_arg() β€” takes a plain argument and crafts parts of the structure with regards to various mount options. if the length is a value less than 0, strlen(3) is used. and heads up: this argument will be referenced until either free_mntarg() or kernel_mount() is called. keep it alive, okay? 🫢
  • mount_argb() β€” adds boolean arguments to the structure. the flag is the boolean value, and name must start with "no", otherwise a panic will occur. NOT a drill. 😭
  • mount_argf() β€” adds printf(9) style arguments to the current structure. πŸŽ€
  • mount_argsu() β€” adds arguments to the structure from a userland string. πŸ¦‹

🌈 EXAMPLES 🌈

an example of the *_cmount() function, serving absolute main character energy:

static int
msdosfs_cmount(struct mntarg *ma, void *data, int flags, struct thread *td)
{
    struct msdosfs_args args;
    int error;

    if (data == NULL)
        return (EINVAL);
    error = copyin(data, &args, sizeof(args));
    if (error)
        return (error);

    ma = mount_argsu(ma, "from", args.fspec, MAXPATHLEN);
    ma = mount_arg(ma, "export", &args.export, sizeof(args.export));
    ma = mount_argf(ma, "uid", "%d", args.uid);
    ma = mount_argf(ma, "gid", "%d", args.gid);
    ma = mount_argf(ma, "mask", "%d", args.mask);
    ma = mount_argf(ma, "dirmask", "%d", args.dirmask);

    ma = mount_argb(ma, args.flags & MSDOSFSMNT_SHORTNAME, "noshortname");
    ma = mount_argb(ma, args.flags & MSDOSFSMNT_LONGNAME, "nolongname");
    ma = mount_argb(ma, !(args.flags & MSDOSFSMNT_NOWIN95), "nowin95");
    ma = mount_argb(ma, args.flags & MSDOSFSMNT_KICONV, "nokiconv");

    ma = mount_argsu(ma, "cs_win", args.cs_win, MAXCSLEN);
    ma = mount_argsu(ma, "cs_dos", args.cs_dos, MAXCSLEN);
    ma = mount_argsu(ma, "cs_local", args.cs_local, MAXCSLEN);

    error = kernel_mount(ma, flags);

    return (error);
}

and when you're working with kernel_vmount(), the varargs must come in pairs, e.g., {name, value}. no solo acts allowed, it's a duo situation. πŸ‘‘

    error = kernel_vmount(
        MNT_RDONLY,
        "fstype", vfsname,
        "fspath", "/",
        "from", path,
        NULL);

πŸ‘€ SEE ALSO πŸ‘€

VFS(9), VFS_MOUNT(9)


⭐ HISTORY ⭐

the kernel_mount() family of functions and this manual page first appeared in FreeBSD 6.0. throwback era fr. πŸ•°οΈ


🫢 AUTHORS 🫢

the kernel_mount() family of functions and API was developed by Poul-Henning Kamp <phk@FreeBSD.org>. and this manual page was written by Tom Rhodes <trhodes@FreeBSD.org>. legends, honestly, we stan. πŸ’œ


and that's the whole page bestie β€” this one came from Debian, dated December 13, 2004, and it's filed under KERNEL_MOUNT(9). go mount something (from inside the kernel, responsibly). bye ily πŸ’–βœ¨

πŸ“¦ where this page comes from