The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
vfs_mount.c File Reference

VFS mount table. More...

#include "vfs.h"
#include "common/string.h"
#include "kernel/sync/spinlock.h"

Macros

#define VFS_MOUNT_MAX   8

Functions

kerr_t vfs_mount (const char *prefix, fs_mount_t *mount)
 mount a filesystem at a path prefix.
kerr_t vfs_umount (const char *prefix)
 unmount the filesystem at an exact path prefix.
bool vfs_mount_at (uint32_t index, char *prefix_out, uint32_t prefix_size, fs_mount_t **mount_out)
 a mounted filesystem, by its place in the mount table (for /proc/mounts).
fs_mount_t * vfs_resolve_mount_path (const char *path, const char **rel_out)
 find the mounted filesystem responsible for an absolute path, and the sub-path relative to that mount's prefix.
kerr_t vfs_mount_root (fs_mount_t *mount)
 mount a filesystem as the root filesystem.

Detailed Description

VFS mount table.

holds the set of mounted filesystems keyed by path prefix. path-based operations resolve a path to the mount whose prefix is the longest match, so "/" (the root) catches everything not claimed by a more specific mount like "/dev" or "/proc". today only root is mounted, but the table makes additional pseudo-filesystems a matter of calling vfs_mount().

Macro Definition Documentation

◆ VFS_MOUNT_MAX

#define VFS_MOUNT_MAX   8

Function Documentation

◆ vfs_mount()

kerr_t vfs_mount ( const char * prefix,
fs_mount_t * mount )

mount a filesystem at a path prefix.

a later, more specific prefix takes precedence over a shorter one during path resolution (e.g. "/dev" wins over "/"). remounting an existing prefix replaces its backing filesystem.

Parameters
prefixabsolute mount point, e.g. "/" or "/dev".
mountthe filesystem to mount there (must already be mounted).
Returns
KERR_OK on success, KERR_INVAL on bad input, KERR_NOSPC if full.

◆ vfs_umount()

kerr_t vfs_umount ( const char * prefix)

unmount the filesystem at an exact path prefix.

Parameters
prefixthe mount point to remove.
Returns
KERR_OK on success, KERR_NOENT if nothing is mounted there.

◆ vfs_mount_at()

bool vfs_mount_at ( uint32_t index,
char * prefix_out,
uint32_t prefix_size,
fs_mount_t ** mount_out )

a mounted filesystem, by its place in the mount table (for /proc/mounts).

Parameters
index0, 1, ... the entries in the order they were mounted.
prefix_outgets the mount point.
mount_outgets the filesystem.
Returns
false when index is past the last entry.

◆ vfs_resolve_mount_path()

fs_mount_t * vfs_resolve_mount_path ( const char * path,
const char ** rel_out )

find the mounted filesystem responsible for an absolute path, and the sub-path relative to that mount's prefix.

the backing filesystem is handed a path relative to its own mount point, not the full absolute path: the root mount "/" sees the path unchanged (still leading '/'), while a sub-mount at "/dev" sees "/fb0" for "/dev/fb0" and "/" for "/dev" itself. the relative path always keeps a leading '/'.

Parameters
pathabsolute path to resolve.
rel_outif non-NULL, receives a pointer into path (or a static "/") for the mount-relative sub-path. only valid while path is.
Returns
the backing mount, or NULL if no filesystem covers the path.

◆ vfs_mount_root()

kerr_t vfs_mount_root ( fs_mount_t * mount)

mount a filesystem as the root filesystem.

convenience wrapper for vfs_mount("/", mount).

Parameters
mountpointer to the filesystem mount structure to be used as the root filesystem.
Returns
KERR_OK on success, or an error code on failure.