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

tmpfs: a filesystem in memory, gone when the system stops. More...

#include <core/system.h>
#include <core/module.h>
#include <core/string.h>
#include <core/panic.h>
#include <core/time.h>
#include <mm/mm.h>
#include <fs/vfs.h>
#include <fs/iobuf.h>
#include <fs/pseudofs.h>
#include <fs/tmpfs.h>
#include <fs/posix.h>
#include <aquila/errno.h>
#include <aquila/dirent.h>

Go to the source code of this file.

Functions

static int tmpfs_vget (struct vnode *super, ino_t ino, struct vnode **vnode)
 Gets a vnode by its inode number, which is its address.
static int tmpfs_close (struct vnode *vnode)
 Frees a vnode that has neither references nor names left.
static ssize_t tmpfs_read (struct vnode *node, off_t offset, struct iobuf *io)
 Reads a file's data from its buffer.
static ssize_t tmpfs_write (struct vnode *node, off_t offset, struct iobuf *io)
 Writes a file's data into its buffer, which grows to hold it.
static int tmpfs_trunc (struct vnode *vnode, off_t len)
 Changes a file's length: its buffer is cut, or grows with zeros.
static int tmpfs_file_can_read (struct file *file, size_t size)
 Says whether size bytes can be read from the file's offset.
static int tmpfs_file_can_write (struct file *file, size_t size)
 Says that a write can always go on: tmpfs has no size limit yet.
static int tmpfs_file_eof (struct file *file)
 Says whether the file's offset is at its end.
static int tmpfs_init ()
 Installs tmpfs at boot.
static int tmpfs_mount (struct vnode *dir, int flags, void *data)
 Mounts a new, empty tmpfs on a directory.

Variables

struct fs tmpfs

Detailed Description

tmpfs: a filesystem in memory, gone when the system stops.

Its vnodes are its inodes: each lives in memory as long as it has a name or a reference, and its inode number is its address. A file's data is one buffer of its size. The directories are pseudofs's (fs/pseudofs/), which devfs and devpts share.

Definition in file tmpfs.c.

Function Documentation

◆ tmpfs_close()

int tmpfs_close ( struct vnode * vnode)
static

Frees a vnode that has neither references nor names left.

Definition at line 38 of file tmpfs.c.

References kfree(), vnode::nlink, vnode::p, pseudofs_close(), vnode::ref, and tmpfs_close().

Referenced by tmpfs_close().

◆ tmpfs_file_can_read()

int tmpfs_file_can_read ( struct file * file,
size_t size )
static

Says whether size bytes can be read from the file's offset.

Definition at line 131 of file tmpfs.c.

References file::offset, vnode::size, and tmpfs_file_can_read().

Referenced by tmpfs_file_can_read().

◆ tmpfs_file_can_write()

int tmpfs_file_can_write ( struct file * file,
size_t size )
static

Says that a write can always go on: tmpfs has no size limit yet.

Definition at line 140 of file tmpfs.c.

References tmpfs_file_can_write().

Referenced by tmpfs_file_can_write().

◆ tmpfs_file_eof()

int tmpfs_file_eof ( struct file * file)
static

Says whether the file's offset is at its end.

Definition at line 146 of file tmpfs.c.

References file::offset, and tmpfs_file_eof().

Referenced by tmpfs_file_eof().

◆ tmpfs_init()

int tmpfs_init ( )
static

Installs tmpfs at boot.

Definition at line 152 of file tmpfs.c.

References tmpfs, tmpfs_init(), and vfs_install().

Referenced by tmpfs_init().

◆ tmpfs_mount()

int tmpfs_mount ( struct vnode * dir,
int flags,
void * data )
static

Mounts a new, empty tmpfs on a directory.

The mode= option (octal) sets its root's permissions, 0777 otherwise. Returns 0, -ENOMEM, or -EBUSY if something is mounted on the directory already.

Definition at line 160 of file tmpfs.c.

References vnode::atime, vnode::ctime, vnode::fs, gettime(), vnode::ino, kfree(), kmalloc(), M_ZERO, vnode::mode, vnode::mtime, vnode::nlink, NULL, vnode::p, vnode::ref, vnode::size, tmpfs, tmpfs_mount(), and vfs_bind().

Referenced by tmpfs_mount().

◆ tmpfs_read()

ssize_t tmpfs_read ( struct vnode * node,
off_t offset,
struct iobuf * io )
static

Reads a file's data from its buffer.

Definition at line 49 of file tmpfs.c.

References iobuf_out(), vnode::p, vnode::size, and tmpfs_read().

Referenced by tmpfs_read().

◆ tmpfs_trunc()

int tmpfs_trunc ( struct vnode * vnode,
off_t len )
static

Changes a file's length: its buffer is cut, or grows with zeros.

Definition at line 95 of file tmpfs.c.

References kfree(), kmalloc(), memcpy(), memset(), MIN, NULL, vnode::p, vnode::size, and tmpfs_trunc().

Referenced by tmpfs_trunc().

◆ tmpfs_vget()

int tmpfs_vget ( struct vnode * super,
ino_t ino,
struct vnode ** vnode )
static

Gets a vnode by its inode number, which is its address.

Definition at line 28 of file tmpfs.c.

References vnode::ino, and tmpfs_vget().

Referenced by tmpfs_vget().

◆ tmpfs_write()

ssize_t tmpfs_write ( struct vnode * node,
off_t offset,
struct iobuf * io )
static

Writes a file's data into its buffer, which grows to hold it.

Definition at line 61 of file tmpfs.c.

References iobuf_in(), kfree(), kmalloc(), M_ZERO, MAX, memcpy(), vnode::p, iobuf::resid, vnode::size, and tmpfs_write().

Referenced by tmpfs_write().

Variable Documentation

◆ tmpfs

struct fs tmpfs

Definition at line 214 of file tmpfs.c.

Referenced by devfs_init(), devpts_init(), tmpfs_init(), and tmpfs_mount().