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

symbolic links across the mounts, and hard links. More...

#include "vfs.h"
#include "common/memory.h"
#include "common/string.h"

Macros

#define FOLLOW_MAX   40

Functions

const char * vfs_inside_root (const char *path, const char *root)
 a real path as a process with this root directory sees it.
bool vfs_join_root (const char *root, const char *virtual_path, char *out, uint32_t size)
 the real path of a path as a process with this root sees it.
kerr_t vfs_follow (char *path, uint32_t size, bool follow_last, const char *root)
 replace the symbolic links along a canonical absolute path by their targets (vfs_link.c).
kerr_t vfs_readlink (const char *path, char *target, uint32_t size)
 read the target of the symbolic link at path, with a NUL.
kerr_t vfs_symlink (const char *path, const char *target)
 make a symbolic link at path to target.
kerr_t vfs_link (const char *old_path, const char *new_path)
 give a file one more name (both paths on one mount, else KERR_INVAL).
kerr_t vfs_mknod (const char *path, uint32_t mode, uint32_t rdev)
 make a named pipe or a device node (fs_ops_t mknod).

Detailed Description

symbolic links across the mounts, and hard links.

the filesystems resolve plain paths only. before an operation, the syscall layer has vfs_follow replace each symbolic link along the path by its target, so the path that reaches the filesystem has no links (but the last name, when the operation acts on a link itself). a target can point into another mount, so each step finds the mount again.

the path is made canonical ("." and ".." removed) before the links are followed, so "link/.." is the directory that holds link, as in a shell's logical mode.

a process can have a root directory of its own (chroot). its paths are then "virtual": "/" is that directory. an absolute link target is taken in the root too, and ".." stops at it.

Macro Definition Documentation

◆ FOLLOW_MAX

#define FOLLOW_MAX   40

Function Documentation

◆ vfs_inside_root()

const char * vfs_inside_root ( const char * path,
const char * root )

a real path as a process with this root directory sees it.

Returns
a pointer into path, or "/"; path itself when it is not under the root.

◆ vfs_join_root()

bool vfs_join_root ( const char * root,
const char * virtual_path,
char * out,
uint32_t size )

the real path of a path as a process with this root sees it.

Returns
false when it does not fit in size.

◆ vfs_follow()

kerr_t vfs_follow ( char * path,
uint32_t size,
bool follow_last,
const char * root )

replace the symbolic links along a canonical absolute path by their targets (vfs_link.c).

Parameters
paththe real path, changed in place.
sizethe size of the path buffer.
follow_lastalso the last name, when it is a link.
rootthe process's root directory ("/" for the real one): an absolute target starts there, and ".." stops there.
Returns
KERR_OK (a missing name is left for the operation to report), KERR_LOOP (too many links), KERR_RANGE (the path got too long).

◆ vfs_readlink()

kerr_t vfs_readlink ( const char * path,
char * target,
uint32_t size )

read the target of the symbolic link at path, with a NUL.

Returns
KERR_OK, KERR_INVAL (not a link), KERR_RANGE, KERR_NOTFOUND.

◆ vfs_symlink()

kerr_t vfs_symlink ( const char * path,
const char * target )

make a symbolic link at path to target.

◆ vfs_link()

kerr_t vfs_link ( const char * old_path,
const char * new_path )

give a file one more name (both paths on one mount, else KERR_INVAL).

Returns
KERR_OK, KERR_ISDIR, KERR_EXIST, KERR_RANGE, KERR_NOTFOUND.

◆ vfs_mknod()

kerr_t vfs_mknod ( const char * path,
uint32_t mode,
uint32_t rdev )

make a named pipe or a device node (fs_ops_t mknod).