Scroll to navigation

R_FS(3) Library Functions Manual R_FS(3)

NAME

r_fsradare2 filesystem library

SYNOPSIS

#include <r_fs.h>

DESCRIPTION

The r_fs library provides filesystem support for radare2, allowing analysis and manipulation of various filesystem types within binary images. It supports mounting, reading, writing, and navigating filesystems embedded in disk images or memory dumps.

Typical usage in the radare2 core allocates a filesystem context with RFS * fs via (void), and mounts a filesystem with r_fs_mount(RFS *fs, const char *fstype, const char *path, ut64 delta), so that commands in the core can list directories, open files and read their contents through the unified API. The core keeps a reference to the returned RFS context (see `libr/core/core.c`), and calls r_fs_free(RFS *fs) when tearing down.

The core structure is RFS, which manages plugins, mounted roots and binds I/O and console operations (see `libr/include/r_fs.h` for fields and types).

INITIALIZATION

RFS * (void)

Creates a new filesystem context with built-in plugins loaded.

void (RFS *fs)

Frees all resources associated with the filesystem context.

MOUNTING

RFSRoot * (RFS *fs, const char *fstype, const char *path, ut64 delta)

Attachs a filesystem implementation (plugin) to a virtual mount point. The `delta` argument is commonly used when the filesystem is found at an offset inside a disk image or memory buffer. In the radare2 core this is typically invoked as:

RFS *fs = r_fs_new();
RFSRoot *root = r_fs_mount (fs, "auto", "/root", core->addr /* offset */);

bool (RFS *fs, const char *path)

Unmounts the filesystem at the specified path.

FILE OPERATIONS

RFSFile * (RFS *fs, const char *path, bool create)

Open a file relative to mounted roots; when multiple roots match the path the first matching root is used. Callers in the core often do:

RFSFile *f = r_fs_open (core->fs, "/some/path", false);
if (f) {
    r_fs_read (core->fs, f, 0, f->size);
    r_fs_close (core->fs, f);
}

void (RFS *fs, RFSFile *file)

Closes an open file handle.

int (RFS *fs, RFSFile *file, ut64 addr, int len)

Reads data from a file at the specified offset.

int (RFS *fs, RFSFile *file, ut64 addr, const ut8 *data, int len)

Writes data to a file at the specified offset.

DIRECTORY OPERATIONS

RList * (RFS *fs, const char *path)

Returns a `RList` of `RFSFile` objects for the given virtual directory. The core uses this to implement the `md` command and directory listings; for example:

RList *files = r_fs_dir (core->fs, "/");
// iterate and inspect file->name, file->size, file->type

bool (RFS *fs, const char *path, const char *name)

Dumps the contents of a directory to disk.

FILE SLURPING

RFSFile * (RFS *fs, const char *path)

Convenience helper that opens and reads a file fully into memory returning an `RFSFile` whose `data` and `size` fields are populated. This is useful when a single buffer is required by consumers (e.g. analysis or dumping).

SEARCHING

RList * (RFS *fs, const char *name, const char *glob)

Finds files by name using glob patterns.

RList * (RFS *fs, const char *name, ut64 off)

Finds files containing data at a specific offset.

PARTITIONS

RList * (RFS *fs, const char *ptype, ut64 delta)

Enumerates partitions using the built-in partition detectors or a specific partition type. The returned list contains `RFSPartition` entries describing start and length; callers often use this to discover filesystems inside disk images before mounting them.

PLUGINS

bool (RFS *fs, RFSPlugin *p)

Adds a filesystem plugin to the context.

bool (RFS *fs, RFSPlugin *p)

Removes a filesystem plugin from the context.

SHELL

bool (RFSShell *shell, RFS *fs, const char *root)

Starts an interactive filesystem shell.

FILE TYPES

const RFSType * (int i)

Retrieves filesystem type information by index.

EXAMPLES

Common patterns used by the radare2 core and plugins:

// create and mount a filesystem at a given offset
RFS *fs = r_fs_new();
RFSRoot *root = r_fs_mount (fs, "fat", "/mnt/fat", 0x1000);

// open, read full contents and close
RFSFile *file = r_fs_open (fs, "/README.txt", false);
if (file) {
    r_fs_read (fs, file, 0, file->size);
    r_fs_close (fs, file);
}

// list a directory
RList *files = r_fs_dir (fs, "/");

// slurp a file into memory (single call)
RFSFile *s = r_fs_slurp (fs, "/config.bin");
if (s) {
    // use s->data and s->size
    r_fs_file_free (s);
}

// find files by name or containing an offset
RList *matches = r_fs_find_name (fs, "/", "*.so");
RList *byoff = r_fs_find_off (fs, "/", 0x2000);

SEE ALSO

r_io(3), r_core(3)

September 20, 2025 Debian