---
name: "r_io"
section: "3"
platform: "linux"
package: "radare2"
version: "6.2.2-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/r_io"
---

# r\_io(3)

Radare2 Input/Output Library API

## NAME

**r\_io** – Radare2 Input/Output Library API

## SYNOPSIS

**#include \<r\_io.h\>**

## DESCRIPTION

The **r\_io** library provides a unified interface for input/output operations in radare2, supporting various backends such as files, memory, network connections, and debuggers. It abstracts file descriptors, memory mappings, caching, and undo functionality.

Key concepts:

- **RIO** is the main structure representing an I/O context.

- **RIODesc** represents an open file or resource descriptor.

- **RIOMap** defines memory mappings from file offsets to virtual addresses.

- **RIOBank** groups maps for banked memory architectures.

- Caching allows temporary modifications without altering the underlying data.

## INITIALIZATION

*RIO* *\** **r\_io\_new**(*void*)

Creates and initializes a new I/O context. *void* **r\_io\_init**(*RIO \*io*)

Initializes an existing I/O structure. *void* **r\_io\_free**(*RIO \*io*)

Frees an I/O context and all associated resources.

## FILE OPERATIONS

*RIODesc* *\** **r\_io\_open**(*RIO \*io*, *const char \*uri*, *int perm*, *int mode*)

Opens a resource specified by URI with given permissions and mode, and maps it at address 0. *RIODesc* *\** **r\_io\_open\_at**(*RIO \*io*, *const char \*uri*, *int perm*, *int mode*, *ut64 at*)

Opens a resource and maps it at the specified address. *bool* **r\_io\_close**(*RIO \*io*)

Closes the current descriptor. *bool* **r\_io\_read\_at**(*RIO \*io*, *ut64 addr*, *ut8 \*buf*, *int len*)

Reads len bytes from virtual address addr into buf. *bool* **r\_io\_write\_at**(*RIO \*io*, *ut64 addr*, *const ut8 \*buf*, *int len*)

Writes len bytes from buf to virtual address addr. *ut64* **r\_io\_seek**(*RIO \*io*, *ut64 offset*, *int whence*)

Seeks to the specified offset. whence can be R\_IO\_SEEK\_SET, R\_IO\_SEEK\_CUR, or R\_IO\_SEEK\_END.

## MEMORY MAPPING

*RIOMap* *\** **r\_io\_map\_add**(*RIO \*io*, *int fd*, *int flags*, *ut64 delta*, *ut64 addr*, *ut64 size*)

Creates a new memory map from file descriptor fd at virtual address addr with size size, starting from file offset delta. *bool* **r\_io\_map\_del**(*RIO \*io*, *ut32 id*)

Deletes the map with the given id. *RIOMap* *\** **r\_io\_map\_get**(*RIO \*io*, *ut32 id*)

Retrieves the map with the given id. *RIOMap* *\** **r\_io\_map\_get\_at**(*RIO \*io*, *ut64 vaddr*)

Gets the map covering the virtual address vaddr.

## BANKING

*RIOBank* *\** **r\_io\_bank\_new**(*const char \*name*)

Creates a new bank with the given name. *bool* **r\_io\_bank\_add**(*RIO \*io*, *RIOBank \*bank*)

Adds a bank to the I/O context. *bool* **r\_io\_bank\_use**(*RIO \*io*, *ut32 bankid*)

Switches to the specified bank.

## CACHING

*bool* **r\_io\_cache\_write\_at**(*RIO \*io*, *ut64 addr*, *const ut8 \*buf*, *int len*)

Writes to the cache at the specified address. *bool* **r\_io\_cache\_read\_at**(*RIO \*io*, *ut64 addr*, *ut8 \*buf*, *int len*)

Reads from the cache at the specified address. *void* **r\_io\_cache\_commit**(*RIO \*io*, *ut64 from*, *ut64 to*, *bool many*)

Commits cached changes to the underlying storage.

## UNDO FUNCTIONALITY

*int* **r\_io\_undo\_init**(*RIO \*io*)

Initializes undo functionality. *void* **r\_io\_undo\_enable**(*RIO \*io*, *int seek*, *int write*)

Enables seek and/or write undo tracking. *void* **r\_io\_wundo\_new**(*RIO \*io*, *ut64 off*, *const ut8 \*data*, *int len*)

Records a write operation for undo.

## EXAMPLES

Opening and reading a file:

```
RIO *io = r_io_new();
RIODesc *desc = r_io_open(io, "/bin/ls", R_PERM_R, 0);
if (desc) {
    ut8 buf[64];
    r_io_read_at(io, 0, buf, sizeof(buf));
}
r_io_free(io);
```

Creating a memory map:

```
RIO *io = r_io_new();
RIODesc *desc = r_io_open_nomap(io, "malloc://1024", R_PERM_RW, 0);
if (desc) {
    RIOMap *map = r_io_map_add(io, desc->fd, R_PERM_RW, 0, 0x1000, 1024);
}
r_io_free(io);
```

Using cache for temporary modifications:

```
RIO *io = r_io_new();
r_io_open(io, "file.bin", R_PERM_RW, 0);
ut8 data[] = {0x90, 0x90}; // NOP NOP
r_io_cache_write_at(io, 0x100, data, 2);
// Changes are cached, not written to file yet
r_io_cache_commit(io, 0x100, 0x102, false);
// Now changes are committed
r_io_free(io);
```

## SEE ALSO

[r\_core(3)](/r_core/3.md), [r\_bin(3)](/r_bin/3.md), [r\_anal(3)](/r_anal/3.md)

## AUTHORS

The radare2 project team.
