miniOS
x86_64 hobby kernel with SMP, VFS, and POSIX process model
Loading...
Searching...
No Matches
tmpfs.c File Reference
#include <miniOS/fs/tmpfs.h>
#include <miniOS/fs/ext2.h>
#include <miniOS/fs/vfs.h>
#include <miniOS/mm/heap.h>
#include <miniOS/io.h>
#include <string.h>
Include dependency graph for tmpfs.c:

Classes

struct  tmpfs_inode_t

Macros

#define TMPFS_MAX_INODES   64
#define TMPFS_BLOCK_SIZE   4096
#define TMPFS_MAX_BLOCKS   16 /* max direct blocks per inode = 64 KiB max file size */
#define TMPFS_ROOT_INO   1
#define TMPFS_NAME_MAX   255

Functions

static tmpfs_inode_ttmpfs_inode_get (uint32_t ino)
static tmpfs_inode_ttmpfs_alloc_inode (uint16_t mode)
static void tmpfs_free_inode (tmpfs_inode_t *ino)
static void * tmpfs_get_or_alloc_block (tmpfs_inode_t *ino, uint32_t bidx)
static int tmpfs_dir_append (tmpfs_inode_t *dir, uint32_t child_ino, const char *name, uint8_t file_type)
static uint32_t tmpfs_dir_find (tmpfs_inode_t *dir, const char *name, uint8_t *ftype_out)
static int tmpfs_dir_remove (tmpfs_inode_t *dir, const char *name)
static uint32_t tmpfs_walk_path (const char *rel_path, uint8_t *ftype_out)
static int tmpfs_lookup (const char *path, vfs_inode_info_t *out)
static int tmpfs_read (uint32_t ino, uint64_t off, void *buf, uint32_t len)
static int tmpfs_write (uint32_t ino, uint64_t off, const void *buf, uint32_t len)
static int tmpfs_readdir (uint32_t ino, uint64_t *offset, vfs_dirent_cb_t cb, void *ud)
static int tmpfs_flush (uint32_t ino)
static void tmpfs_set_active_root (uint32_t ino)
static int tmpfs_truncate (uint32_t ino, uint64_t new_size)
static int tmpfs_readlink (uint32_t ino, char *buf, uint32_t len)

Variables

static tmpfs_inode_t g_tmpfs_inodes [TMPFS_MAX_INODES]
static uint32_t g_tmpfs_next_ino = TMPFS_ROOT_INO
static int g_tmpfs_initialized = 0
static uint32_t g_tmpfs_active_root = TMPFS_ROOT_INO

: Symlink filename (null-terminated; max TMPFS_NAME_MAX chars).

tmpfs_symlink() - Create a symlink in a tmpfs directory. @parent_ino: Parent directory inode number.

@target: Target string (null-terminated; max 255 chars stored).

Returns
: 0 on success, -1 on error (name too long, inode table full, etc.).
static vfs_ops_t g_tmpfs_ops
static int tmpfs_symlink (uint32_t parent_ino, const char *name, const char *target)
static int tmpfs_chmod (uint32_t ino, uint16_t mode)
static int tmpfs_rename (uint32_t old_parent_ino, const char *old_name, uint32_t new_parent_ino, const char *new_name)
static int tmpfs_statfs (vfs_statfs_t *out)
static int tmpfs_fs_mount (const char *source, const char *target, const void *data)
void tmpfs_init (void)
vfs_ops_ttmpfs_get_ops (void)
uint32_t tmpfs_alloc_root (void)
int tmpfs_create (uint32_t parent_ino, const char *name, uint16_t mode, uint32_t *new_ino_out)
int tmpfs_create_device (uint32_t parent_ino, const char *name, uint8_t device_type, uint32_t *new_ino_out)
int tmpfs_mknod (uint32_t parent_ino, const char *name, uint16_t mode, uint32_t dev, uint32_t *new_ino_out)
int tmpfs_mkdir (uint32_t parent_ino, const char *name, uint32_t *new_ino_out)
int tmpfs_unlink (uint32_t parent_ino, const char *name)
int tmpfs_rmdir (uint32_t parent_ino, const char *name)

Macro Definition Documentation

◆ TMPFS_BLOCK_SIZE

#define TMPFS_BLOCK_SIZE   4096

◆ TMPFS_MAX_BLOCKS

#define TMPFS_MAX_BLOCKS   16 /* max direct blocks per inode = 64 KiB max file size */

◆ TMPFS_MAX_INODES

#define TMPFS_MAX_INODES   64

◆ TMPFS_NAME_MAX

#define TMPFS_NAME_MAX   255

◆ TMPFS_ROOT_INO

#define TMPFS_ROOT_INO   1

Function Documentation

◆ tmpfs_alloc_inode()

tmpfs_inode_t * tmpfs_alloc_inode ( uint16_t mode)
static
Here is the caller graph for this function:

◆ tmpfs_alloc_root()

uint32_t tmpfs_alloc_root ( void )

tmpfs_alloc_root() - Allocate a fresh root directory inode for a new mount.

Each call to mount tmpfs <target> should call this to get an isolated root directory. The returned inode number is stored in vfs_mount_t.root_ino and activated via set_root() before each path lookup on that mount.

Returns
: New inode number, or 0 on failure (inode table full).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tmpfs_chmod()

int tmpfs_chmod ( uint32_t ino,
uint16_t mode )
static
Here is the call graph for this function:

◆ tmpfs_create()

int tmpfs_create ( uint32_t parent_ino,
const char * name,
uint16_t mode,
uint32_t * new_ino_out )
Here is the call graph for this function:

◆ tmpfs_create_device()

int tmpfs_create_device ( uint32_t parent_ino,
const char * name,
uint8_t device_type,
uint32_t * new_ino_out )
Here is the call graph for this function:

◆ tmpfs_dir_append()

int tmpfs_dir_append ( tmpfs_inode_t * dir,
uint32_t child_ino,
const char * name,
uint8_t file_type )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tmpfs_dir_find()

uint32_t tmpfs_dir_find ( tmpfs_inode_t * dir,
const char * name,
uint8_t * ftype_out )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tmpfs_dir_remove()

int tmpfs_dir_remove ( tmpfs_inode_t * dir,
const char * name )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tmpfs_flush()

int tmpfs_flush ( uint32_t ino)
static

◆ tmpfs_free_inode()

void tmpfs_free_inode ( tmpfs_inode_t * ino)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tmpfs_fs_mount()

int tmpfs_fs_mount ( const char * source,
const char * target,
const void * data )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tmpfs_get_ops()

vfs_ops_t * tmpfs_get_ops ( void )

tmpfs_get_ops() - Return a pointer to the static tmpfs vfs_ops_t table.

The returned pointer is valid for the lifetime of the kernel.

Returns
: Pointer to static vfs_ops_t with lookup, read, readdir, write, flush set.

◆ tmpfs_get_or_alloc_block()

void * tmpfs_get_or_alloc_block ( tmpfs_inode_t * ino,
uint32_t bidx )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tmpfs_init()

void tmpfs_init ( void )

tmpfs_init() - Initialise the tmpfs inode pool and register the "tmpfs" type.

Initialises the shared inode table (inode 1 = internal sentinel root) and calls register_filesystem("tmpfs", ...) so that vfs_mount_fstype("tmpfs", ...) works. Safe to call multiple times — subsequent calls are no-ops. Must be called before any vfs_mount_fstype("tmpfs", ...) invocation.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tmpfs_inode_get()

tmpfs_inode_t * tmpfs_inode_get ( uint32_t ino)
static
Here is the caller graph for this function:

◆ tmpfs_lookup()

int tmpfs_lookup ( const char * path,
vfs_inode_info_t * out )
static
Here is the call graph for this function:

◆ tmpfs_mkdir()

int tmpfs_mkdir ( uint32_t parent_ino,
const char * name,
uint32_t * new_ino_out )
Here is the call graph for this function:

◆ tmpfs_mknod()

int tmpfs_mknod ( uint32_t parent_ino,
const char * name,
uint16_t mode,
uint32_t dev,
uint32_t * new_ino_out )
Here is the call graph for this function:

◆ tmpfs_read()

int tmpfs_read ( uint32_t ino,
uint64_t off,
void * buf,
uint32_t len )
static
Here is the call graph for this function:

◆ tmpfs_readdir()

int tmpfs_readdir ( uint32_t ino,
uint64_t * offset,
vfs_dirent_cb_t cb,
void * ud )
static
Here is the call graph for this function:

◆ tmpfs_readlink()

int tmpfs_readlink ( uint32_t ino,
char * buf,
uint32_t len )
static

tmpfs_readlink() - Read the stored symlink_target of a tmpfs symlink inode. @ino: Inode number (must have i_mode & EXT2_S_IFLNK set). @buf: Output buffer. NOT null-terminated (POSIX readlink semantics). @len: Maximum bytes to copy.

Returns
: Number of bytes copied (>= 0), or -1 if not a symlink or error.
Here is the call graph for this function:

◆ tmpfs_rename()

int tmpfs_rename ( uint32_t old_parent_ino,
const char * old_name,
uint32_t new_parent_ino,
const char * new_name )
static
Here is the call graph for this function:

◆ tmpfs_rmdir()

int tmpfs_rmdir ( uint32_t parent_ino,
const char * name )
Here is the call graph for this function:

◆ tmpfs_set_active_root()

void tmpfs_set_active_root ( uint32_t ino)
static

◆ tmpfs_statfs()

int tmpfs_statfs ( vfs_statfs_t * out)
static

◆ tmpfs_symlink()

int tmpfs_symlink ( uint32_t parent_ino,
const char * name,
const char * target )
static
Here is the call graph for this function:

◆ tmpfs_truncate()

int tmpfs_truncate ( uint32_t ino,
uint64_t new_size )
static
Here is the call graph for this function:

◆ tmpfs_unlink()

int tmpfs_unlink ( uint32_t parent_ino,
const char * name )
Here is the call graph for this function:

◆ tmpfs_walk_path()

uint32_t tmpfs_walk_path ( const char * rel_path,
uint8_t * ftype_out )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tmpfs_write()

int tmpfs_write ( uint32_t ino,
uint64_t off,
const void * buf,
uint32_t len )
static
Here is the call graph for this function:

Variable Documentation

◆ g_tmpfs_active_root

uint32_t g_tmpfs_active_root = TMPFS_ROOT_INO
static

◆ g_tmpfs_initialized

int g_tmpfs_initialized = 0
static

◆ g_tmpfs_inodes

tmpfs_inode_t g_tmpfs_inodes[TMPFS_MAX_INODES]
static

◆ g_tmpfs_next_ino

uint32_t g_tmpfs_next_ino = TMPFS_ROOT_INO
static

◆ g_tmpfs_ops

vfs_ops_t g_tmpfs_ops
static
Initial value:
= {
.lookup = tmpfs_lookup,
.read = tmpfs_read,
.readdir = tmpfs_readdir,
.write = tmpfs_write,
.flush = tmpfs_flush,
.create = tmpfs_create,
.unlink = tmpfs_unlink,
.rename = tmpfs_rename,
.mkdir = tmpfs_mkdir,
.rmdir = tmpfs_rmdir,
.set_root = tmpfs_set_active_root,
.truncate = tmpfs_truncate,
.readlink = tmpfs_readlink,
.symlink = tmpfs_symlink,
.mknod = tmpfs_mknod,
.chmod = tmpfs_chmod,
.statfs = tmpfs_statfs,
}
static int tmpfs_read(uint32_t ino, uint64_t off, void *buf, uint32_t len)
Definition tmpfs.c:274
static int tmpfs_lookup(const char *path, vfs_inode_info_t *out)
Definition tmpfs.c:247
static int tmpfs_write(uint32_t ino, uint64_t off, const void *buf, uint32_t len)
Definition tmpfs.c:298
static int tmpfs_readlink(uint32_t ino, char *buf, uint32_t len)
Definition tmpfs.c:382
static int tmpfs_chmod(uint32_t ino, uint16_t mode)
Definition tmpfs.c:434
static int tmpfs_symlink(uint32_t parent_ino, const char *name, const char *target)
Definition tmpfs.c:406
static int tmpfs_flush(uint32_t ino)
Definition tmpfs.c:341
static int tmpfs_readdir(uint32_t ino, uint64_t *offset, vfs_dirent_cb_t cb, void *ud)
Definition tmpfs.c:318
static int tmpfs_rename(uint32_t old_parent_ino, const char *old_name, uint32_t new_parent_ino, const char *new_name)
Definition tmpfs.c:442
static int tmpfs_statfs(vfs_statfs_t *out)
Definition tmpfs.c:499
static void tmpfs_set_active_root(uint32_t ino)
Definition tmpfs.c:346
static int tmpfs_truncate(uint32_t ino, uint64_t new_size)
Definition tmpfs.c:350
int tmpfs_rmdir(uint32_t parent_ino, const char *name)
Definition tmpfs.c:696
int tmpfs_unlink(uint32_t parent_ino, const char *name)
Definition tmpfs.c:681
int tmpfs_mkdir(uint32_t parent_ino, const char *name, uint32_t *new_ino_out)
Definition tmpfs.c:659
int tmpfs_mknod(uint32_t parent_ino, const char *name, uint16_t mode, uint32_t dev, uint32_t *new_ino_out)
Definition tmpfs.c:625
int tmpfs_create(uint32_t parent_ino, const char *name, uint16_t mode, uint32_t *new_ino_out)
Definition tmpfs.c:589