Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Appendix D: Compatibility Matrix

This appendix provides detailed compatibility information between libmagic-rs and other file identification tools, magic file formats, and system environments.

GNU file Compatibility

Command-Line Interface

GNU file Optionrmagic EquivalentStatusNotes
file <file>rmagic <file>✅ CompleteBasic file identification
file -i <file>rmagic --mime-type <file>📋 PlannedMIME type output
file -b <file>rmagic --brief <file>📋 PlannedBrief output (no filename)
file -m <magic>rmagic --magic-file <magic>✅ CompleteCustom magic file
file -z <file>rmagic --compress <file>📋 PlannedLook inside compressed files
file -L <file>rmagic --follow-symlinks <file>📋 PlannedFollow symbolic links
file -h <file>rmagic --no-follow-symlinks <file>📋 PlannedDon't follow symlinks
file -f <list>rmagic --files-from <list>📋 PlannedRead filenames from file
file -F <sep>rmagic --separator <sep>📋 PlannedCustom field separator
file -0rmagic --print0📋 PlannedNUL-separated output
file --jsonrmagic --json✅ CompleteJSON output format

Output Format Compatibility

Text Output

# GNU file
$ file example.elf
example.elf: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked

# rmagic (current)
$ rmagic example.elf
example.elf: ELF 64-bit LSB executable

# rmagic (planned)
$ rmagic example.elf
example.elf: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked

MIME Type Output

# GNU file
$ file -i example.pdf
example.pdf: application/pdf; charset=binary

# rmagic (planned)
$ rmagic --mime-type example.pdf
example.pdf: application/pdf; charset=binary

JSON Output

# GNU file (recent versions)
$ file --json example.elf
[{"filename":"example.elf","mime-type":"application/x-pie-executable","mime-encoding":"binary","description":"ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked"}]

# rmagic (current)
$ rmagic --json example.elf
{
  "filename": "example.elf",
  "description": "ELF 64-bit LSB executable",
  "mime_type": "application/x-executable",
  "confidence": 1.0
}

Magic File Format Compatibility

FeatureGNU filermagicStatusNotes
Basic patternsCompleteString, numeric matching
Hierarchical rules🔄In ProgressParent-child relationships
Indirect offsets📋PlannedPointer dereferencing
Relative offsets📋PlannedPosition-relative addressing
Search patterns📋PlannedPattern searching in ranges
Bitwise operationsCompleteAND, OR operations
String operations📋PlannedCase-insensitive, regex
Date/time formats📋PlannedUnix timestamps, etc.
Floating point📋PlannedFloat, double types
Unicode support📋PlannedUTF-8, UTF-16 strings

libmagic C Library Compatibility

API Compatibility

libmagic Functionrmagic EquivalentStatusNotes
magic_open()MagicDatabase::new()Database initialization
magic_load()MagicDatabase::load_from_file()🔄Magic file loading
magic_file()MagicDatabase::evaluate_file()🔄File evaluation
magic_buffer()MagicDatabase::evaluate_buffer()📋Buffer evaluation
magic_setflags()EvaluationConfigConfiguration options
magic_close()Drop traitAutomatic cleanup
magic_error()Result<T, LibmagicError>Error handling

Flag Compatibility

libmagic Flagrmagic EquivalentStatusNotes
MAGIC_NONEDefault behaviorStandard file identification
MAGIC_DEBUGDebug logging📋Planned
MAGIC_SYMLINKfollow_symlinks: true📋Planned
MAGIC_COMPRESSdecompress: true📋Planned
MAGIC_DEVICEScheck_devices: true📋Planned
MAGIC_MIME_TYPEoutput_format: MimeType📋Planned
MAGIC_CONTINUEstop_at_first_match: falseMultiple matches
MAGIC_CHECKValidation mode📋Planned
MAGIC_PRESERVE_ATIMEpreserve_atime: true📋Planned
MAGIC_RAWraw_output: true📋Planned

Platform Compatibility

Operating Systems

PlatformStatusNotes
Linux✅ CompletePrimary development platform
macOS✅ CompleteFull support with native builds
Windows✅ CompleteMSVC and GNU toolchain support
FreeBSD✅ CompleteBSD compatibility
OpenBSD✅ CompleteBSD compatibility
NetBSD✅ CompleteBSD compatibility
Solaris📋 PlannedShould work with Rust support
AIX📋 PlannedDepends on Rust availability

Architectures

ArchitectureStatusNotes
x86_64✅ CompletePrimary target architecture
i686✅ Complete32-bit x86 support
aarch64✅ CompleteARM 64-bit (Apple Silicon, etc.)
armv7✅ CompleteARM 32-bit
riscv64✅ CompleteRISC-V 64-bit
powerpc64✅ CompletePowerPC 64-bit
s390x✅ CompleteIBM System z
mips64📋 PlannedMIPS 64-bit
sparc64📋 PlannedSPARC 64-bit

Rust Version Compatibility

Rust VersionStatusNotes
1.85+✅ RequiredMinimum supported version
1.84❌ Not supportedMissing required features
1.83❌ Not supportedMissing required features
Stable✅ SupportedAlways targets stable Rust
Beta✅ SupportedShould work with beta releases
Nightly⚠️ Best effortMay work but not guaranteed

File Format Support

Executable Formats

FormatGNU filermagicStatusNotes
ELFCompleteLinux/Unix executables
PE/COFF📋PlannedWindows executables
Mach-O📋PlannedmacOS executables
a.out📋PlannedLegacy Unix format
Java Class📋PlannedJVM bytecode
WebAssembly📋PlannedWASM modules

Archive Formats

FormatGNU filermagicStatusNotes
ZIP📋PlannedZIP archives
TAR📋PlannedTape archives
RAR📋PlannedRAR archives
7-Zip📋Planned7z archives
ar📋PlannedUnix archives
CPIO📋PlannedCPIO archives

Image Formats

FormatGNU filermagicStatusNotes
JPEG📋PlannedJPEG images
PNG📋PlannedPNG images
GIF📋PlannedGIF images
BMP📋PlannedWindows bitmaps
TIFF📋PlannedTIFF images
WebP📋PlannedWebP images
SVG📋PlannedSVG vector graphics

Document Formats

FormatGNU filermagicStatusNotes
PDF📋PlannedPDF documents
PostScript📋PlannedPS/EPS files
RTF📋PlannedRich Text Format
MS Office📋PlannedDOC, XLS, PPT
OpenDocument📋PlannedODF formats
HTML📋PlannedHTML documents
XML📋PlannedXML documents

Performance Comparison

Benchmark Results (Preliminary)

Test CaseGNU filermagicRatioNotes
Single ELF file2.1ms1.8ms1.17x fasterMemory-mapped I/O advantage
1000 small files180ms165ms1.09x fasterReduced startup overhead
Large file (1GB)45ms42ms1.07x fasterEfficient memory mapping
Magic file loading12ms8ms1.5x fasterOptimized parsing

Note: Benchmarks are preliminary and may vary by system and file types.

Memory Usage

ScenarioGNU filermagicNotes
Base memory~2MB~1.5MBSmaller runtime footprint
Magic database~8MB~6MBMore efficient storage
Large file processing~16MB~2MBMemory-mapped I/O

Migration Guide

From GNU file

Command Line Migration

# Old GNU file commands
file document.pdf
file -i document.pdf
file -b document.pdf
file -m custom.magic document.pdf

# New rmagic commands
rmagic document.pdf
rmagic --mime-type document.pdf     # Planned
rmagic --brief document.pdf         # Planned
rmagic --magic-file custom.magic document.pdf

Script Migration

#!/bin/bash
# Old script using GNU file
for f in *.bin; do
    type=$(file -b "$f")
    echo "File $f is: $type"
done

# New script using rmagic
for f in *.bin; do
    type=$(rmagic --brief "$f")  # Planned
    echo "File $f is: $type"
done

From libmagic C Library

C Code Migration

// Old libmagic C code
#include <magic.h>

magic_t magic = magic_open(MAGIC_MIME_TYPE);
magic_load(magic, NULL);
const char* result = magic_file(magic, "file.bin");
printf("MIME type: %s\n", result);
magic_close(magic);
#![allow(unused)]
fn main() {
// New Rust code
use libmagic_rs::{MagicDatabase, EvaluationConfig};

let mut config = EvaluationConfig::default();
config.output_format = OutputFormat::MimeType;  // Planned

let db = MagicDatabase::load_default()?;
let result = db.evaluate_file("file.bin")?;
println!("MIME type: {}", result.mime_type.unwrap_or_default());
}

Known Limitations

Current Limitations

  1. Incomplete Magic File Support: Not all GNU file magic syntax is implemented
  2. Limited File Format Coverage: Focus on common formats initially
  3. No Compression Support: Cannot look inside compressed files yet
  4. Basic MIME Type Support: Limited MIME type database
  5. No Plugin System: Cannot extend with custom detectors

Planned Improvements

  1. Complete Magic File Compatibility: Full GNU file magic syntax support
  2. Comprehensive Format Support: Support for all major file formats
  3. Advanced Features: Compression, encryption detection
  4. Performance Optimization: Parallel processing, caching
  5. Extended APIs: More flexible configuration options

Testing Compatibility

Test Suite Coverage

Test CategoryGNU file Testsrmagic TestsCoverage
Basic formats500+7915%
Magic file parsing200+5025%
Error handling100+2929%
Performance50+00%
CompatibilityN/A00%

Compatibility Test Plan

  1. Format Detection Tests: Validate against GNU file results
  2. Magic File Tests: Test with real-world magic databases
  3. Performance Tests: Compare speed and memory usage
  4. API Tests: Validate library interface compatibility
  5. Cross-platform Tests: Ensure consistent behavior across platforms

This compatibility matrix will be updated as development progresses and more features are implemented.