#mount #wrapper #util-linux #libmount #api-bindings

rsmount

Safe Rust wrapper around the util-linux/libmount C library

1 unstable release

0.1.0 Oct 28, 2024

#662 in Filesystem

Download history 128/week @ 2024-10-28 3/week @ 2024-11-18 31/week @ 2024-12-02 37/week @ 2024-12-09

71 downloads per month

Apache-2.0 OR MIT

2MB
16K SLoC

Contains (WOFF font, 26KB) Atkinson-Hyperlegible-BoldItalic-102.woff, (WOFF font, 24KB) Atkinson-Hyperlegible-Bold-102.woff, (WOFF font, 25KB) Atkinson-Hyperlegible-Italic-102.woff, (WOFF font, 23KB) Atkinson-Hyperlegible-Regular-102.woff, (WOFF font, 17KB) Atkinson-Hyperlegible-Bold-102a.woff2, (WOFF font, 19KB) Atkinson-Hyperlegible-BoldItalic-102a.woff2 and 2 more.

rsmount


Crates.io Version docs.rs Crates.io MSRV Crates.io License

⚠️ WARNING: This library is still in development, thus not yet suitable for use in production.

The rsmount library is a safe Rust wrapper around util-linux/libmount.

rsmount allows users to, among other things:

  • mount devices on an operating system’s file hierarchy,
  • list/manage mount points in /proc/<pid>/mountinfo,
  • consult the system’s swap usage from /proc/swaps,
  • compose/edit /etc/fstab, the file describing all devices an OS should mount at boot.
  • etc.

Usage

This crate requires libmount version 2.39.2 or later.

Add the following to your Cargo.toml:

[dependencies]
rsmount = "0.1.0"

Then install the system packages below before running cargo build:

  • util-linux: to generate Rust bindings from libmount's header files.
  • libclang: to satisfy the dependency of bindgen on libclang.
  • pkg-config: to detect system libraries.

Read the installation instructions below to install the required dependencies on your system.

Documentation (docs.rs)

Example

In this example we mount a disk on /mnt/backup.

use rsmount::core::device::BlockDevice;
use rsmount::core::flags::MountFlag;
use rsmount::core::fs::FileSystem;
use rsmount::mount::Mount;

fn main() -> rsmount::Result<()> {
    // Configure the `Mount` struct.
    let block_device: BlockDevice = "/dev/vda".parse()?;
    let mut mount = Mount::builder()
        // Device to mount.
        .source(block_device.into())
        // Location of the mount point in the file tree.
        .target("/mnt/backup")
        // Do not allow writing to the file system while it is mounted.
        .mount_flags(vec![MountFlag::ReadOnly])
        // Gives a hint about the file system used by the device (optional).
        .file_system(FileSystem::Ext4)
        .build()?;

    // Mount `/dev/vda` at `/mnt/backup`.
    mount.mount_device()?;

    Ok(())
}

Install required dependencies

Alpine Linux

As root, issue the following command:

apk add util-linux-dev clang-libclang pkgconfig

NixOS

Install the packages in a temporary environment with:

nix-shell -p util-linux.dev libclang.lib pkg-config

or permanently with:

nix-env -iA nixos.util-linux.dev nixos.libclang.lib nixos.pkg-config

Ubuntu

sudo apt-get install libmount-dev libclang-dev pkg-config

License

This project is licensed under either of the following:

at your discretion.

Files in the third-party/ and web-snapshots/ directories are subject to their own licenses and/or copyrights.

SPDX-License-Identifier: Apache-2.0 OR MIT

Copyright (c) 2023 Nick Piaddo

Dependencies

~1.7–4.5MB
~78K SLoC