AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
link.c File Reference

Links by path: hard links (link()), symbolic links (symlink(), readlink()), and renaming (rename()). More...

#include <core/system.h>
#include <fs/vfs.h>
#include <aquila/fcntl.h>

Go to the source code of this file.

Functions

int vfs_link (const char *oldpath, struct uio *ouio, const char *newpath, struct uio *nuio)
 Makes a hard link: a new name for an existing file, in the same mounted filesystem.
int vfs_symlink (const char *target, const char *path, struct uio *uio)
 Makes a symbolic link.
ssize_t vfs_readlink (const char *path, struct uio *uio, char *buf, size_t size)
 Reads what a symbolic link contains.
static int entry_get (struct vnode *dir, const char *name, struct vnode **ref)
 Gets the vnode of the entry name of dir, or NULL in *ref if there is none.
int vfs_rename (const char *oldpath, struct uio *ouio, const char *newpath, struct uio *nuio)
 Renames a file or a directory, possibly to another directory of the same mounted filesystem.

Detailed Description

Links by path: hard links (link()), symbolic links (symlink(), readlink()), and renaming (rename()).

Definition in file link.c.

Function Documentation

◆ entry_get()

int entry_get ( struct vnode * dir,
const char * name,
struct vnode ** ref )
static

Gets the vnode of the entry name of dir, or NULL in *ref if there is none.

Returns 0 or a negative errno.

Definition at line 127 of file link.c.

References entry_get(), NULL, vfs_finddir(), and vfs_vget().

Referenced by entry_get(), and vfs_rename().

◆ vfs_link()

int vfs_link ( const char * oldpath,
struct uio * ouio,
const char * newpath,
struct uio * nuio )

Makes a hard link: a new name for an existing file, in the same mounted filesystem.

Directories can't be linked.

Parameters
oldpaththe file's path, followed if it's a symbolic link unless ouio has O_NOFOLLOW
ouiowho is asking, and the directory oldpath is relative to
newpaththe new name's path
nuiowho is asking, and the directory newpath is relative to
Returns
0, -EPERM for a directory, -EEXIST, -EXDEV across filesystems, or another negative errno

Definition at line 24 of file link.c.

References kfree(), vnode::mode, NULL, vfs_access(), vfs_close(), vfs_link(), vfs_lookup_dir(), vfs_lookup_parent(), vfs_mount_root_of(), vfs_vlink(), VFS_W, and VFS_X.

Referenced by do_linkat(), and vfs_link().

◆ vfs_readlink()

ssize_t vfs_readlink ( const char * path,
struct uio * uio,
char * buf,
size_t size )

Reads what a symbolic link contains.

Parameters
paththe link's path (not followed)
uiowho is asking
bufwhere the contents go, not NUL-terminated
sizethe buffer's size
Returns
the number of bytes read, -EINVAL if path isn't a symbolic link, or a negative errno

Definition at line 105 of file link.c.

References uio::flags, MIN, vnode::mode, NULL, vnode::size, vfs_close(), vfs_lookup(), vfs_read(), and vfs_readlink().

Referenced by creat_path(), sys_readlinkat(), and vfs_readlink().

◆ vfs_rename()

int vfs_rename ( const char * oldpath,
struct uio * ouio,
const char * newpath,
struct uio * nuio )

Renames a file or a directory, possibly to another directory of the same mounted filesystem.

An entry at the new name is replaced: a file by a file, or an empty directory by a directory.

Parameters
oldpaththe path it has
ouiowho is asking, and the directory oldpath is relative to
newpaththe path it gets
nuiothe directory newpath is relative to
Returns
0, -ENOENT, -EXDEV, -EINVAL to move a directory into itself, -ENOTDIR, -EISDIR, -ENOTEMPTY, or another negative errno

Definition at line 154 of file link.c.

References entry_get(), kfree(), NULL, vfs_access(), vfs_close(), vfs_dir_empty(), vfs_lookup_parent(), vfs_mount_root_of(), vfs_rename(), vfs_under(), vfs_vrename(), VFS_W, and VFS_X.

Referenced by sys_renameat(), and vfs_rename().

◆ vfs_symlink()

int vfs_symlink ( const char * target,
const char * path,
struct uio * uio )

Makes a symbolic link.

Parameters
targetwhat the link contains (not checked: it may not exist)
paththe link's path
uiowho is asking
Returns
0, -ENOENT for an empty target, or a negative errno

Definition at line 72 of file link.c.

References NULL, vfs_close(), vfs_mknod(), vfs_symlink(), vfs_unlink(), and vfs_write().

Referenced by sys_symlinkat(), and vfs_symlink().