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 corrupt`](cli::app::Commands::Corrupt) | Intentionally corrupt pages for testing |
32//! | [`inno recover`](cli::app::Commands::Recover) | Assess page-level recoverability and count salvageable records |
33//! | [`inno find`](cli::app::Commands::Find) | Search data directory for pages by number |
34//! | [`inno tsid`](cli::app::Commands::Tsid) | List or find tablespace IDs |
35//! | [`inno sdi`](cli::app::Commands::Sdi) | Extract SDI metadata (MySQL 8.0+) |
36//! | [`inno log`](cli::app::Commands::Log) | Analyze InnoDB redo log files |
37//! | [`inno info`](cli::app::Commands::Info) | Inspect ibdata1, compare LSNs, query MySQL |
38//!
39//! ## Global options
40//!
41//! All subcommands accept `--color <auto|always|never>` and `--output <file>`.
42//! Most subcommands also accept `--json` for machine-readable output and
43//! `--page-size` to override auto-detection.
44//!
45//! See the [`cli`] module for full details.
46//!
47//! # Library API
48//!
49//! Add `idb` as a dependency to use the parsing library directly:
50//!
51//! ```toml
52//! [dependencies]
53//! idb = { package = "innodb-utils", version = "1" }
54//! ```
55//!
56//! ## Quick example
57//!
58//! ```no_run
59//! use idb::innodb::tablespace::Tablespace;
60//! use idb::innodb::checksum::validate_checksum;
61//! use idb::innodb::page::FilHeader;
62//!
63//! // Open a tablespace (page size is auto-detected from page 0)
64//! let mut ts = Tablespace::open("table.ibd").unwrap();
65//!
66//! // Read and inspect a page
67//! let page = ts.read_page(0).unwrap();
68//! let header = FilHeader::parse(&page).unwrap();
69//! println!("Page type: {}", header.page_type);
70//!
71//! // Validate the page checksum
72//! let result = validate_checksum(&page, ts.page_size(), None);
73//! println!("Checksum valid: {}", result.valid);
74//! ```
75//!
76//! ## Key entry points
77//!
78//! | Type / Function | Purpose |
79//! |-----------------|---------|
80//! | [`Tablespace`](innodb::tablespace::Tablespace) | Open `.ibd` files, read pages, iterate |
81//! | [`FilHeader`](innodb::page::FilHeader) | Parse the 38-byte header on every InnoDB page |
82//! | [`PageType`](innodb::page_types::PageType) | Map page type codes to names and descriptions |
83//! | [`validate_checksum`](innodb::checksum::validate_checksum) | CRC-32C, legacy, and MariaDB full\_crc32 validation |
84//! | [`extract_sdi_from_pages`](innodb::sdi::extract_sdi_from_pages) | SDI metadata extraction (MySQL 8.0+) |
85//! | [`LogFile`](innodb::log::LogFile) | Read and inspect redo log files |
86//! | [`VendorInfo`](innodb::vendor::VendorInfo) | Detected vendor (MySQL / Percona / MariaDB) and format details |
87//!
88//! ## Module overview
89//!
90//! | Module | Purpose |
91//! |--------|---------|
92//! | [`innodb::tablespace`] | File I/O, page size detection, page iteration |
93//! | [`innodb::page`] | FIL header/trailer, FSP header parsing |
94//! | [`innodb::page_types`] | Page type enum with names and descriptions |
95//! | [`innodb::checksum`] | CRC-32C and legacy InnoDB checksum algorithms |
96//! | [`innodb::index`] | INDEX page internals (B+Tree header, FSEG) |
97//! | [`innodb::record`] | Row-level record parsing (compact format) |
98//! | [`innodb::sdi`] | SDI metadata extraction and decompression |
99//! | [`innodb::log`] | Redo log file structure and block parsing |
100//! | [`innodb::undo`] | UNDO log page structures |
101//! | [`innodb::lob`] | Large object (BLOB/LOB) page headers |
102//! | [`innodb::compression`] | Compression detection and decompression |
103//! | [`innodb::encryption`] | Encryption detection from FSP flags |
104//! | [`innodb::vendor`] | Vendor detection (MySQL, Percona, MariaDB) and format info |
105//! | [`innodb::constants`] | InnoDB page/file structure constants |
106//!
107//! ## Feature flags
108//!
109//! | Feature | Default | Description |
110//! |---------|---------|-------------|
111//! | `mysql` | off | Enables live MySQL queries via `mysql_async` + `tokio` (used by `inno info`). |
112
113pub mod cli;
114pub mod innodb;
115pub mod util;
116
117use thiserror::Error;
118
119/// Errors returned by `idb` operations.
120#[derive(Error, Debug)]
121pub enum IdbError {
122 /// An I/O error occurred (file open, read, seek, or write failure).
123 #[error("I/O error: {0}")]
124 Io(String),
125
126 /// A parse error occurred (malformed binary data or unexpected values).
127 #[error("Parse error: {0}")]
128 Parse(String),
129
130 /// An invalid argument was supplied (out-of-range page number, bad option, etc.).
131 #[error("Invalid argument: {0}")]
132 Argument(String),
133}