VFSSUBR(9)

πŸ“¦ version 11.0, in nixpkgs unstable

πŸ’… VFSSUBR(9) β€” high-level interface to kernel file system interface πŸ’…

okay bestie, welcome to VFSSUBR(9) from the Kernel Developer's Manual. this page is literally all about the high-level interface to the kernel file system interface (VFS), and it's giving very β€œmain character energy in sys/kern” ✨.


✨ NAME ✨

the whole squad is: vfssubr, vfs_getnewfsid, vfs_getvfs, vfs_export, vfs_showexport, vfs_export_lookup, vfs_setpublicfs, vfs_mountedon, vfs_mountroot, vfs_unmountall, vfs_busy, vfs_unbusy, vfs_mountalloc, vfs_rootmountalloc, vfs_shutdown, vfs_attach, vfs_detach, vfs_reinit, vfs_getopsbyname, vfs_suspend, vfs_resume, vfs_vnode_iterator_init, vfs_vnode_iterator_destroy, vfs_vnode_iterator_next β€” high-level interface to kernel file system interface. periodt. πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

first, include these iconic headers:

#include <sys/param.h>
#include <sys/mount.h>
#include <sys/vnode.h>

then the prototypes, exactly as the page serves them:

void
vfs_getnewfsid(struct mount *mp);

struct mount *
vfs_getvfs(fsid_t *fsid);

int
vfs_export_lookup(struct mount *mp, struct netexport *nep,
    struct export_args *argp);

int
vfs_setpublicfs(struct mount *mp, struct netexport *nep,
    struct export_args *argp);

int
vfs_mountedon(struct vnode *vp);

int
vfs_mountroot(void);

void
vfs_unmountall(struct lwp *l);

int
vfs_busy(struct mount *mp);

void
vfs_unbusy(struct mount *mp);

struct mount *
vfs_mountalloc(struct vfsops *vfs, struct vnode *vp);

int
vfs_rootmountalloc(char *fstypename, char *devname, struct mount **mpp);

void
vfs_shutdown(void);

int
vfs_attach(struct vfsops *vfs);

int
vfs_detach(struct vfsops *vfs);

void
vfs_reinit(void);

struct vfsops *
vfs_getopsbyname(const char *name);

int
vfs_suspend(struct mount *mp, int nowait);

void
vfs_resume(struct mount *mp);

void
vfs_vnode_iterator_init(struct mount *mp, struct vnode_iterator **vip);

void
vfs_vnode_iterator_destroy(struct vnode_iterator *vi);

struct vnode *
vfs_vnode_iterator_next(struct vnode_iterator *vi,
    bool (*selector)(void *context, struct vnode *vpp), void *context);

🌸 DESCRIPTION 🌸

the high-level functions described on this page are the interface to the kernel file system interface (VFS). that's the whole vibe: kernel file system glue, but make it documented. 🫢


πŸŽ€ FUNCTIONS πŸŽ€

🧚 vfs_getnewfsid(mp)

gets a new unique file system id type for the file system specified by the mount structure mp. the file system id type is stored in mp->mnt_stat.f_fsidx. slay, identifiers. πŸ’–

πŸ” vfs_getvfs(fsid)

looks up a mount point with the file system identifier fsid. cute lil mount-point finder behavior.

πŸ” vfs_export_lookup(mp, nep, argp)

checks client permission on the exportable file system specified by the mount structure mp. the page says the argument nam is the address of the networked client. this function is used by file system type specific functions to verify that the client can access the file system. no cap, it's an access-check girlie. πŸ’…

🌍 vfs_setpublicfs(mp, nep, argp)

sets the publicly exported file system specified by the mount structure mp.

🧲 vfs_mountedon(vp)

checks to see if a file system is mounted on a block device specified by the vnode vp. it's giving β€œis something already here?” energy.

🌱 vfs_mountroot(void)

mounts the root file system. the origin story. the main character mount. πŸ‘‘

🧹 vfs_unmountall(l)

unmounts all file systems. all of them. bye besties. 🫢

πŸ”’ vfs_busy(mp)

marks the mount point specified by mp as busy and gets a reference to it. this function is used to synchronize access and to delay unmounting.

⚠️ the caller must hold a pre-existing reference to the mount.

πŸ”“ vfs_unbusy(mp)

undoes a vfs_busy() on the mount point specified by mp. the un-busy-ing. the release. the β€œyou may go” moment.

πŸ—οΈ vfs_mountalloc(vfsops, vp)

allocates and initialises a mount structure, setting mnt_vnodecovered to vp and mnt_op to vfsops. on success it returns the address of the mount structure. otherwise, it returns NULL. ngl, straightforward icon behavior. ✨

🌳 vfs_rootmountalloc(fstypename, devname, mpp)

looks up a file system type specified by the name fstypename, and if found, allocates and initialises a mount structure for it. the allocated mount structure is marked as busy and returned in the address specified by mpp. the device the root file system was mounted from is specified by the argument devname and is recorded in the new mount structure. root-mount allocation with receipts. 🧾

πŸ›‘ vfs_shutdown()

syncs and unmounts all file systems before shutting down. invoked by cpu_reboot(9). literally the β€œeverybody out of the pool” function. 🌊

🧩 vfs_attach(vfs)

establishes file system vfs and initialises it. attach era. πŸ¦‹

πŸͺ„ vfs_detach(vfs)

removes file system vfs from the kernel. detach era. bye boo. πŸ‘‹

♻️ vfs_reinit(void)

reinitialises all file systems within the kernel through file system-specific vfs operation (see vfsops(9)). it's a glow-up pass for every file system in the kernel. ✨

πŸ“› vfs_getopsbyname(name)

given a file system name specified by name, looks up the vfs operations for that file system (see vfsops(9)), or returns NULL if the file system isn't present in the kernel. name-based lookup, bestie. iykyk. πŸ’…

😴 vfs_suspend(mp, nowait)

requests a mounted file system to suspend all operations. all new operations to the file system are stopped. after all operations in progress have completed, the file system is synced to disk and the function returns. if a file system suspension is currently in progress and nowait is set, EWOULDBLOCK is returned. if the operation is successful, zero is returned; otherwise an appropriate error code is returned. very β€œhold please, we're syncing” energy. 😭

🌀️ vfs_resume(mp)

requests a mounted file system to resume operations. wake up bestie, we're operating again. πŸ’–

πŸͺž vfs_vnode_iterator_init(mp, vip)

allocates and initializes an iterator vip over all vnodes attached to mount point mp. iterator era begins. πŸŽ€

🧽 vfs_vnode_iterator_destroy(vi)

frees all resources associated with an iterator vi. cleanup is self-care. 🌸

πŸ‘€ vfs_vnode_iterator_next(vi, selector, context)

returns the next vnode from iterator vi. if the operation is successful, the vnode has a reference added to it and it is returned. if the iterator is exhausted, the function returns NULL.

if an optional selector function is provided, then this function is called with the context provided and the candidate vnode to be returned. if the selector returns false, then the vnode is skipped; if it returns true, the vnode is referenced and then returned. selector says yes? slay. selector says no? skipped. no cap. βœ…


πŸ”₯ CODE REFERENCES πŸ”₯

the vfs interface functions are implemented within the files sys/kern/vfs_mount.c, sys/kern/vfs_subr.c and sys/kern/vfs_init.c. those are the source files, bestie β€” go read them if you want the deep lore. πŸ“š


πŸ‘‘ SEE ALSO πŸ‘‘


🌷 cute lil footer note: this page's source/version energy is Debian, dated April 17, 2017, and the manual is VFSSUBR(9) β€” mwah! πŸ’–

πŸ“¦ where this page comes from