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

cpiofs: the RAM disk as a filesystem, read straight from an archive in the old binary cpio format. More...

#include <core/system.h>
#include <core/module.h>
#include <core/panic.h>
#include <core/time.h>
#include <fs/vfs.h>
#include <fs/initramfs.h>
#include <fs/iobuf.h>
#include <fs/posix.h>
#include <fs/rofs.h>
#include <cpio.h>

Go to the source code of this file.

Macros

#define MAX_NAMESIZE   1024

Functions

static void cpio_dirent_name (struct dirent *dirent, const char *name)
 Copies an entry's name into a struct dirent, cut to fit.
static int cpio_root_node (struct vnode *super, struct vnode **ref)
 Makes the root directory's vnode, for the archive on device super.
static int cpio_new_node (const char *name, struct cpio_hdr *hdr, size_t sz, size_t data, struct vnode *sp, struct vnode **ref)
 Makes the vnode of an archive member: its name, its header, its data's size and where the data starts in the archive.
static struct vnode * cpio_new_child_node (struct vnode *parent, struct vnode *child)
 Adds a vnode to a directory's entries.
static struct vnode * cpio_find (struct vnode *root, const char *path)
 Finds the vnode at a path from the root, while the archive is loaded.
static int cpio_finddir (struct vnode *root, const char *name, struct dirent *dirent)
 Finds the entry of a directory that has a name; .. is the directory's parent.
static int cpio_vget (struct vnode *super, ino_t ino, struct vnode **vnode)
 Gets a vnode by its inode number, which is its address.
static int cpio_load (struct vnode *dev, struct vnode **super)
 Loads the archive on a device: the root directory, then a vnode for each member, linked into its directory, until the archive's trailer.
static ssize_t cpio_read (struct vnode *vnode, off_t offset, struct iobuf *io)
 Reads a file's data, from the archive.
static ssize_t cpio_readdir (struct vnode *node, off_t offset, struct dirent *dirent)
 Reads a directory's entry at an offset.
static int cpio_close (struct vnode *vnode)
 Releases a vnode: nothing to do, the tree stays in memory.
static int cpio_eof (struct file *file)
 Says whether an open file (or directory) is at its end.
static int cpio_init ()
 Registers cpiofs as an archiver for the RAM disk, at boot.

Variables

struct fs cpiofs

Detailed Description

cpiofs: the RAM disk as a filesystem, read straight from an archive in the old binary cpio format.

Loading the archive walks its members once and builds a tree of vnodes in memory, one for each member, linked into its directory; a file's data stays in the archive, where its vnode says it starts. The filesystem is read-only.

Definition in file cpio.c.

Macro Definition Documentation

◆ MAX_NAMESIZE

#define MAX_NAMESIZE   1024

Definition at line 273 of file cpio.c.

Referenced by cpio_load().

Function Documentation

◆ cpio_close()

int cpio_close ( struct vnode * vnode)
static

Releases a vnode: nothing to do, the tree stays in memory.

Definition at line 414 of file cpio.c.

References cpio_close().

Referenced by cpio_close().

◆ cpio_dirent_name()

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

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

Definition at line 27 of file cpio.c.

References cpio_dirent_name(), and memcpy().

Referenced by cpio_dirent_name(), cpio_finddir(), and cpio_readdir().

◆ cpio_eof()

int cpio_eof ( struct file * file)
static

Says whether an open file (or directory) is at its end.

A directory's offset counts its . and .. entries too (cpio_readdir()).

Definition at line 421 of file cpio.c.

References cpio::count, cpio_eof(), and file::offset.

Referenced by cpio_eof().

◆ cpio_find()

struct vnode * cpio_find ( struct vnode * root,
const char * path )
static

Finds the vnode at a path from the root, while the archive is loaded.

Returns NULL if there's none.

Definition at line 180 of file cpio.c.

References cpio_find(), cpio::dir, vnode::mode, NULL, and vnode::p.

Referenced by cpio_find(), and cpio_load().

◆ cpio_finddir()

int cpio_finddir ( struct vnode * root,
const char * name,
struct dirent * dirent )
static

Finds the entry of a directory that has a name; .. is the directory's parent.

Returns 0, -ENOENT, or -ENOTDIR.

Definition at line 226 of file cpio.c.

References cpio_dirent_name(), cpio_finddir(), cpio::dir, vnode::mode, cpio::name, vnode::p, and cpio::parent.

Referenced by cpio_finddir().

◆ cpio_init()

int cpio_init ( )
static

Registers cpiofs as an archiver for the RAM disk, at boot.

Definition at line 431 of file cpio.c.

References cpio_init(), cpiofs, and initramfs_archiver_register().

Referenced by cpio_init().

◆ cpio_load()

int cpio_load ( struct vnode * dev,
struct vnode ** super )
static

Loads the archive on a device: the root directory, then a vnode for each member, linked into its directory, until the archive's trailer.

A member that isn't in the old binary format panics: the kernel has no root without it. A member whose directory isn't in the archive is skipped. Returns 0, or -ENOMEM.

Definition at line 280 of file cpio.c.

References CPIO_BIN_MAGIC, cpio_find(), cpio_load(), cpio_new_child_node(), cpio_new_node(), cpio_root_node(), cpio_hdr::filesize, cpio_hdr::magic, MAX_NAMESIZE, MIN, cpio_hdr::namesize, NULL, panic, printk(), vnode::size, and vfs_read().

Referenced by cpio_load().

◆ cpio_new_child_node()

struct vnode * cpio_new_child_node ( struct vnode * parent,
struct vnode * child )
static

Adds a vnode to a directory's entries.

Returns the vnode, or NULL if either is missing or parent isn't a directory.

Definition at line 156 of file cpio.c.

References cpio::count, cpio_new_child_node(), cpio::dir, vnode::mode, cpio::next, NULL, vnode::p, and cpio::parent.

Referenced by cpio_load(), and cpio_new_child_node().

◆ cpio_new_node()

int cpio_new_node ( const char * name,
struct cpio_hdr * hdr,
size_t sz,
size_t data,
struct vnode * sp,
struct vnode ** ref )
static

Makes the vnode of an archive member: its name, its header, its data's size and where the data starts in the archive.

Returns 0 or -ENOMEM.

Definition at line 98 of file cpio.c.

References cpio::count, cpio_new_node(), cpiofs, cpio::data, cpio::dir, vnode::fs, vnode::gid, vnode::ino, kfree(), kmalloc(), M_ZERO, cpio_hdr::mode, vnode::mode, cpio_hdr::mtime, vnode::mtime, cpio::name, cpio::next, cpio_hdr::nlink, vnode::nlink, NULL, vnode::p, cpio::parent, cpio_hdr::rdev, vnode::rdev, vnode::size, cpio::super, timespec::tv_sec, and vnode::uid.

Referenced by cpio_load(), and cpio_new_node().

◆ cpio_read()

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

Reads a file's data, from the archive.

Definition at line 360 of file cpio.c.

References cpio_read(), vnode::p, vnode::size, and vfs_read_io().

Referenced by cpio_read().

◆ cpio_readdir()

ssize_t cpio_readdir ( struct vnode * node,
off_t offset,
struct dirent * dirent )
static

Reads a directory's entry at an offset.

The entries are . and .. first, then its members. Returns 1 if an entry was read, or 0 past the last one.

Definition at line 379 of file cpio.c.

References cpio::count, cpio_dirent_name(), cpio_readdir(), and vnode::p.

Referenced by cpio_readdir().

◆ cpio_root_node()

int cpio_root_node ( struct vnode * super,
struct vnode ** ref )
static

Makes the root directory's vnode, for the archive on device super.

Returns 0 or -ENOMEM.

Definition at line 40 of file cpio.c.

References vnode::atime, cpio::count, cpio_root_node(), cpiofs, vnode::ctime, cpio::data, cpio::dir, vnode::fs, gettime(), vnode::gid, vnode::ino, kfree(), kmalloc(), M_ZERO, vnode::mode, vnode::mtime, cpio::next, vnode::nlink, NULL, vnode::p, cpio::parent, vnode::ref, vnode::size, cpio::super, and vnode::uid.

Referenced by cpio_load(), and cpio_root_node().

◆ cpio_vget()

int cpio_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 267 of file cpio.c.

References cpio_vget(), and vnode::ino.

Referenced by cpio_vget().

Variable Documentation

◆ cpiofs

struct fs cpiofs

Definition at line 436 of file cpio.c.

Referenced by cpio_init(), cpio_new_node(), and cpio_root_node().