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

pseudofs: the directories of the filesystems that live in memory (tmpfs, and so devfs and devpts). More...

#include <core/system.h>
#include <core/time.h>
#include <fs/pseudofs.h>

Go to the source code of this file.

Functions

static void pseudofs_dirent_name (struct dirent *dirent, const char *name)
 Copies an entry's name into a struct dirent, cut to fit.
int pseudofs_vmknod (struct vnode *dir, const char *fn, mode_t mode, dev_t dev, struct uio *uio, struct vnode **ref)
 Makes a node in a directory: a new vnode, owned by the caller, and an entry for it.
static struct pseudofs_dirent * entry_find (struct vnode *dir, const char *fn, struct pseudofs_dirent **prev)
 Finds the entry fn of directory dir, and the entry before it in *prev (NULL if it's the first).
static void entry_remove (struct vnode *dir, struct pseudofs_dirent *entry, struct pseudofs_dirent *prev)
 Removes entry (which comes after prev) from directory dir, and drops a link to its vnode, which is freed if nothing references it.
int pseudofs_vunlink (struct vnode *vnode, const char *fn, struct uio *uio)
 Removes an entry from a directory.
int pseudofs_vlink (struct vnode *dir, const char *fn, struct vnode *vnode, struct uio *uio)
 Adds an entry for an existing vnode (a hard link) to a directory.
int pseudofs_vrename (struct vnode *odir, const char *ofn, struct vnode *ndir, const char *nfn, struct uio *uio)
 Renames an entry, possibly to another directory, replacing an entry at the new name.
int pseudofs_setattr (struct vnode *vnode)
 Stores a vnode's attributes: there's nothing to do, since they only live in the vnode.
ssize_t pseudofs_readdir (struct vnode *dir, off_t offset, struct dirent *dirent)
 Reads a directory's entry at an offset.
int pseudofs_finddir (struct vnode *dir, const char *name, struct dirent *dirent)
 Finds the entry of a directory that has a name.
int pseudofs_close (struct vnode *vnode)
 Frees a vnode that has no names or references left, and its cached pages.

Variables

static const char dotdot [] = ".."

Detailed Description

pseudofs: the directories of the filesystems that live in memory (tmpfs, and so devfs and devpts).

A directory is a list of its entries, each a name and the entry's vnode, which is also its inode (its inode number is its address).

Definition in file pseudofs.c.

Function Documentation

◆ entry_find()

struct pseudofs_dirent * entry_find ( struct vnode * dir,
const char * fn,
struct pseudofs_dirent ** prev )
static

Finds the entry fn of directory dir, and the entry before it in *prev (NULL if it's the first).

Returns NULL if there's none.

Definition at line 134 of file pseudofs.c.

References entry_find(), NULL, and vnode::p.

Referenced by entry_find(), pseudofs_vlink(), pseudofs_vrename(), and pseudofs_vunlink().

◆ entry_remove()

void entry_remove ( struct vnode * dir,
struct pseudofs_dirent * entry,
struct pseudofs_dirent * prev )
static

Removes entry (which comes after prev) from directory dir, and drops a link to its vnode, which is freed if nothing references it.

Definition at line 150 of file pseudofs.c.

References pseudofs_dirent::d_ino, pseudofs_dirent::d_name, entry_remove(), kfree(), vnode::mode, pseudofs_dirent::next, vnode::nlink, vnode::p, vnode::ref, and vfs_close().

Referenced by entry_remove(), pseudofs_vrename(), and pseudofs_vunlink().

◆ pseudofs_close()

int pseudofs_close ( struct vnode * vnode)

Frees a vnode that has no names or references left, and its cached pages.

Its names belong to the directory entries, which were freed when they were removed.

Parameters
vnodethe vnode
Returns
0

Definition at line 397 of file pseudofs.c.

References kfree(), pseudofs_close(), and vnode_pages_free().

Referenced by pseudofs_close(), and tmpfs_close().

◆ pseudofs_dirent_name()

void pseudofs_dirent_name ( struct dirent * dirent,
const char * name )
static

Copies an entry's name into a struct dirent, cut to fit.

Definition at line 26 of file pseudofs.c.

References memcpy(), and pseudofs_dirent_name().

Referenced by pseudofs_dirent_name(), pseudofs_finddir(), and pseudofs_readdir().

◆ pseudofs_finddir()

int pseudofs_finddir ( struct vnode * dir,
const char * name,
struct dirent * dirent )

Finds the entry of a directory that has a name.

Parameters
dirthe directory
namethe name
direntthe entry, filled in
Returns
0, -ENOENT, -ENOTDIR, or -EINVAL

Definition at line 367 of file pseudofs.c.

References vnode::mode, pseudofs_dirent::next, vnode::p, pseudofs_dirent_name(), and pseudofs_finddir().

Referenced by pseudofs_finddir(), and pseudofs_vmknod().

◆ pseudofs_readdir()

ssize_t pseudofs_readdir ( struct vnode * dir,
off_t offset,
struct dirent * dirent )

Reads a directory's entry at an offset.

The entries are . and .. first, then the list's entries (except its own ..).

Parameters
dirthe directory
offsetwhich entry
direntthe entry, filled in
Returns
1 if an entry was read, or 0 past the last one

Definition at line 320 of file pseudofs.c.

References dotdot(), pseudofs_dirent::next, vnode::p, pseudofs_dirent_name(), and pseudofs_readdir().

Referenced by pseudofs_readdir().

◆ pseudofs_setattr()

int pseudofs_setattr ( struct vnode * vnode)

Stores a vnode's attributes: there's nothing to do, since they only live in the vnode.

Parameters
vnodethe vnode
Returns
0

Definition at line 306 of file pseudofs.c.

References pseudofs_setattr().

Referenced by pseudofs_setattr().

◆ pseudofs_vlink()

int pseudofs_vlink ( struct vnode * dir,
const char * fn,
struct vnode * vnode,
struct uio * uio )

Adds an entry for an existing vnode (a hard link) to a directory.

Parameters
dirthe directory
fnthe new name
vnodethe vnode
uiowho is asking
Returns
0, -EEXIST, -ENAMETOOLONG, or -ENOMEM

Definition at line 211 of file pseudofs.c.

References pseudofs_dirent::d_ino, pseudofs_dirent::d_name, entry_find(), kfree(), kmalloc(), pseudofs_dirent::next, vnode::nlink, vnode::p, and pseudofs_vlink().

Referenced by pseudofs_vlink().

◆ pseudofs_vmknod()

int pseudofs_vmknod ( struct vnode * dir,
const char * fn,
mode_t mode,
dev_t dev,
struct uio * uio,
struct vnode ** ref )

Makes a node in a directory: a new vnode, owned by the caller, and an entry for it.

A new directory gets its .. entry.

Parameters
dirthe directory
fnthe new node's name
modeits type (S_IF*) and permissions
devits device number, for a device node
uiowho is asking (the owner)
refif not NULL, set to the new vnode
Returns
0, -EEXIST, -ENAMETOOLONG, or -ENOMEM

Definition at line 49 of file pseudofs.c.

References vnode::atime, vnode::ctime, pseudofs_dirent::d_ino, pseudofs_dirent::d_name, dotdot(), vnode::fs, gettime(), uio::gid, vnode::gid, vnode::ino, kfree(), kmalloc(), M_ZERO, vnode::mode, vnode::mtime, pseudofs_dirent::next, vnode::nlink, NULL, vnode::p, pseudofs_finddir(), pseudofs_vmknod(), vnode::rdev, vnode::size, uio::uid, and vnode::uid.

Referenced by pseudofs_vmknod().

◆ pseudofs_vrename()

int pseudofs_vrename ( struct vnode * odir,
const char * ofn,
struct vnode * ndir,
const char * nfn,
struct uio * uio )

Renames an entry, possibly to another directory, replacing an entry at the new name.

The VFS has checked the replaced entry already (its type, that a directory is empty).

Parameters
odirthe directory the entry is in
ofnits name
ndirthe directory it goes to
nfnits new name
uiowho is asking
Returns
0, -ENOENT, -ENAMETOOLONG, or -ENOMEM

Definition at line 250 of file pseudofs.c.

References pseudofs_dirent::d_ino, pseudofs_dirent::d_name, dotdot(), entry_find(), entry_remove(), kfree(), vnode::mode, pseudofs_dirent::next, vnode::nlink, vnode::p, and pseudofs_vrename().

Referenced by pseudofs_vrename().

◆ pseudofs_vunlink()

int pseudofs_vunlink ( struct vnode * vnode,
const char * fn,
struct uio * uio )

Removes an entry from a directory.

Parameters
vnodethe directory
fnthe entry's name
uiowho is asking
Returns
0, -ENOTDIR, or -ENOENT

Definition at line 186 of file pseudofs.c.

References entry_find(), entry_remove(), vnode::mode, and pseudofs_vunlink().

Referenced by pseudofs_vunlink().

Variable Documentation

◆ dotdot

const char dotdot[] = ".."
static

Definition at line 23 of file pseudofs.c.