Skip to main content

idb/
lib.rs

1//! InnoDB file analysis toolkit.
2//!
3//! The `innodb-utils` crate (library name `idb`) provides Rust types and
4//! functions for parsing, inspecting, and manipulating InnoDB tablespace
5//! files (`.ibd`), redo log files, and system tablespace data (`ibdata1`).
6//!
7//! # CLI Reference
8//!
9//! Install the `inno` binary and use its subcommands to work with InnoDB
10//! files from the command line.
11//!
12//! ## Installation
13//!
14//! ```text
15//! cargo install innodb-utils          # crates.io
16//! brew install ringo380/tap/inno      # Homebrew (macOS/Linux)
17//! ```
18//!
19//! Pre-built binaries for Linux and macOS (x86_64 + aarch64) are available
20//! on the [GitHub releases page](https://github.com/ringo380/idb-utils/releases).
21//!
22//! ## Subcommands
23//!
24//! | Command | Purpose |
25//! |---------|---------|
26//! | [`inno parse`](cli::app::Commands::Parse) | Parse `.ibd` file and display page summary |
27//! | [`inno pages`](cli::app::Commands::Pages) | Detailed page structure analysis (INDEX, UNDO, LOB, SDI) |
28//! | [`inno dump`](cli::app::Commands::Dump) | Hex dump of raw page bytes |
29//! | [`inno checksum`](cli::app::Commands::Checksum) | Validate page checksums (CRC-32C, legacy, MariaDB full\_crc32) |
30//! | [`inno diff`](cli::app::Commands::Diff) | Compare two tablespace files page-by-page |
31//! | [`inno watch`](cli::app::Commands::Watch) | Monitor a tablespace file for page-level changes |
32//! | [`inno corrupt`](cli::app::Commands::Corrupt) | Intentionally corrupt pages for testing |
33//! | [`inno recover`](cli::app::Commands::Recover) | Assess page-level recoverability and count salvageable records |
34//! | [`inno find`](cli::app::Commands::Find) | Search data directory for pages by number |
35//! | [`inno tsid`](cli::app::Commands::Tsid) | List or find tablespace IDs |
36//! | [`inno sdi`](cli::app::Commands::Sdi) | Extract SDI metadata (MySQL 8.0+) |
37//! | [`inno log`](cli::app::Commands::Log) | Analyze InnoDB redo log files |
38//! | [`inno info`](cli::app::Commands::Info) | Inspect ibdata1, compare LSNs, query MySQL |
39//!
40//! ## Global options
41//!
42//! All subcommands accept `--color <auto|always|never>` and `--output <file>`.
43//! Most subcommands also accept `--json` for machine-readable output and
44//! `--page-size` to override auto-detection.
45//!
46//! See the [`cli`] module for full details.
47//!
48//! # Library API
49//!
50//! Add `idb` as a dependency to use the parsing library directly:
51//!
52//! ```toml
53//! [dependencies]
54//! idb = { package = "innodb-utils", version = "1" }
55//! ```
56//!
57//! ## Quick example
58//!
59//! ```no_run
60//! use idb::innodb::tablespace::Tablespace;
61//! use idb::innodb::checksum::validate_checksum;
62//! use idb::innodb::page::FilHeader;
63//!
64//! // Open a tablespace (page size is auto-detected from page 0)
65//! let mut ts = Tablespace::open("table.ibd").unwrap();
66//!
67//! // Read and inspect a page
68//! let page = ts.read_page(0).unwrap();
69//! let header = FilHeader::parse(&page).unwrap();
70//! println!("Page type: {}", header.page_type);
71//!
72//! // Validate the page checksum
73//! let result = validate_checksum(&page, ts.page_size(), None);
74//! println!("Checksum valid: {}", result.valid);
75//! ```
76//!
77//! ## Key entry points
78//!
79//! | Type / Function | Purpose |
80//! |-----------------|---------|
81//! | [`Tablespace`](innodb::tablespace::Tablespace) | Open `.ibd` files, read pages, iterate |
82//! | [`FilHeader`](innodb::page::FilHeader) | Parse the 38-byte header on every InnoDB page |
83//! | [`PageType`](innodb::page_types::PageType) | Map page type codes to names and descriptions |
84//! | [`validate_checksum`](innodb::checksum::validate_checksum) | CRC-32C, legacy, and MariaDB full\_crc32 validation |
85//! | [`extract_sdi_from_pages`](innodb::sdi::extract_sdi_from_pages) | SDI metadata extraction (MySQL 8.0+) |
86//! | [`LogFile`](innodb::log::LogFile) | Read and inspect redo log files |
87//! | [`VendorInfo`](innodb::vendor::VendorInfo) | Detected vendor (MySQL / Percona / MariaDB) and format details |
88//!
89//! ## Module overview
90//!
91//! | Module | Purpose |
92//! |--------|---------|
93//! | [`innodb::tablespace`] | File I/O, page size detection, page iteration |
94//! | [`innodb::page`] | FIL header/trailer, FSP header parsing |
95//! | [`innodb::page_types`] | Page type enum with names and descriptions |
96//! | [`innodb::checksum`] | CRC-32C and legacy InnoDB checksum algorithms |
97//! | [`innodb::index`] | INDEX page internals (B+Tree header, FSEG) |
98//! | [`innodb::record`] | Row-level record parsing (compact format) |
99//! | [`innodb::sdi`] | SDI metadata extraction and decompression |
100//! | [`innodb::log`] | Redo log file structure and block parsing |
101//! | [`innodb::undo`] | UNDO log page structures |
102//! | [`innodb::lob`] | Large object (BLOB/LOB) page headers |
103//! | [`innodb::compression`] | Compression detection and decompression |
104//! | [`innodb::encryption`] | Encryption detection and encryption info parsing |
105//! | [`innodb::decryption`] | AES-256-CBC page decryption with keyring support |
106//! | [`innodb::keyring`] | MySQL `keyring_file` plugin binary format reader |
107//! | [`innodb::vendor`] | Vendor detection (MySQL, Percona, MariaDB) and format info |
108//! | [`innodb::constants`] | InnoDB page/file structure constants |
109//!
110//! ## Feature flags
111//!
112//! | Feature | Default | Description |
113//! |---------|---------|-------------|
114//! | `mysql` | off | Enables live MySQL queries via `mysql_async` + `tokio` (used by `inno info`). |
115
116pub mod cli;
117pub mod innodb;
118pub mod util;
119
120use thiserror::Error;
121
122/// Errors returned by `idb` operations.
123#[derive(Error, Debug)]
124pub enum IdbError {
125    /// An I/O error occurred (file open, read, seek, or write failure).
126    #[error("I/O error: {0}")]
127    Io(String),
128
129    /// A parse error occurred (malformed binary data or unexpected values).
130    #[error("Parse error: {0}")]
131    Parse(String),
132
133    /// An invalid argument was supplied (out-of-range page number, bad option, etc.).
134    #[error("Invalid argument: {0}")]
135    Argument(String),
136}