mount-fstab 0.1.1

Type-safe /etc/fstab parsing, editing, and validation library
Documentation

mount-fstab

Crates.io Documentation CI License: MIT MSRV

A 100% type-safe, memory-safe, thread-safe Rust library for parsing, editing, validating, and writing /etc/fstab files.

Implements the official fstab(5) semantics from util-linux, aligned with libmount and glibc parsing behavior.

Quick Start

use mount_fstab::{Entry, Fstab, FsType, MountPoint, Options, Spec};

// Parse an fstab file
let input = "\
# /etc/fstab
UUID=abc-123 / ext4 defaults 0 1
UUID=def-456 /boot ext4 defaults 0 2
/swap.img none swap sw 0 0
";
let fstab = Fstab::parse_str(input).unwrap();

// Inspect entries
assert_eq!(fstab.len(), 3);
let root = fstab.root().unwrap();
assert!(root.file.is_root());

// Edit entries
let mut fstab = Fstab::parse_str(input).unwrap();
fstab
    .add(Entry::builder()
        .spec(Spec::parse("UUID=data").unwrap())
        .file(MountPoint::new("/data").unwrap())
        .vfstype(FsType::parse("ext4").unwrap())
        .options(Options::parse("defaults,noatime").unwrap())
        .build()
        .unwrap())
    .remove(1); // Remove /boot

// Validate
for diag in fstab.validate() {
    eprintln!("{:?}: {}", diag.severity, diag.message);
}

// Atomic write
fstab.write_atomic("/etc/fstab").unwrap();

Features

  • Parse -- Full fstab(5) format: all tag types (LABEL, UUID, PARTLABEL, PARTUUID, ID), NFS mounts, escape sequences, comments
  • Edit -- CRUD API with order preservation and comment tracking
  • Validate -- Semantic checks matching findmnt --verify
  • Serialize -- Display formatting with proper escape encoding
  • Atomic write -- tempfile -> fsync -> rename for safe file updates
  • Type safety -- Every field is a validated type, not a raw string
  • serde -- Optional Serialize/Deserialize support

Installation

[dependencies]
mount-fstab = "0.1"

For serde support:

[dependencies]
mount-fstab = { version = "0.1", features = ["serde"] }

Minimum Supported Rust Version

Rust 1.95 or later.

License

Licensed under the MIT license. See LICENSE for details.