High level FFI binding around the sys mount & umount2 calls, for Rust

Related tags

Filesystem sys-mount
Overview

sys-mount

Rust Compatibility License

High level FFI bindings to the mount and umount2 system calls, for Rust.

Examples

Mount

This is how the mount command could be written with this API.

extern crate clap;
extern crate sys_mount;

use clap::{App, Arg};
use sys_mount::{Mount, MountFlags, SupportedFilesystems};
use std::process::exit;

fn main() {
    let matches = App::new("mount")
        .arg(Arg::with_name("source").required(true))
        .arg(Arg::with_name("directory").required(true))
        .get_matches();

    let src = matches.value_of("source").unwrap();
    let dir = matches.value_of("directory").unwrap();

    // Fetch a listed of supported file systems on this system. This will be used
    // as the fstype to `Mount::new`, as the `Auto` mount parameter.
    let supported = match SupportedFilesystems::new() {
        Ok(supported) => supported,
        Err(why) => {
            eprintln!("failed to get supported file systems: {}", why);
            exit(1);
        }
    };

    // The source block will be mounted to the target directory, and the fstype is likely
    // one of the supported file systems.
    match Mount::new(src, dir, &supported, MountFlags::empty(), None) {
        Ok(mount) => {
            println!("mounted {} ({}) to {}", src, mount.get_fstype(), dir);
        }
        Err(why) => {
            eprintln!("failed to mount {} to {}: {}", src, dir, why);
            exit(1);
        }
    }
}

Umount

This is how the umount command could be implemented.

extern crate clap;
extern crate sys_mount;

use clap::{App, Arg};
use sys_mount::{unmount, UnmountFlags};
use std::process::exit;

fn main() {
    let matches = App::new("umount")
        .arg(Arg::with_name("lazy")
            .short("l")
            .long("lazy"))
        .arg(Arg::with_name("source").required(true))
        .get_matches();

    let src = matches.value_of("source").unwrap();

    let flags = if matches.is_present("lazy") {
        UnmountFlags::DETACH
    } else {
        UnmountFlags::empty()
    };

    match unmount(src, flags) {
        Ok(()) => (),
        Err(why) => {
            eprintln!("failed to unmount {}: {}", src, why);
            exit(1);
        }
    }
}
Comments
  • Add a

    Add a "loop" feature to make loopback functionality optional

    Add a "loop" feature to make loopback functionality optional

    This allows omitting the loopdev dependency and its dependency tree, which has grown substantial. Disabling the loop feature brings sys-mount from 55 dependencies to 7.

    opened by joshtriplett 4
  • MountFlags's type should be c_ulong

    MountFlags's type should be c_ulong

    On some architectures c_ulong isn't u64, resulting in build errors such as:

    error[E0308]: mismatched types
       --> .../sys-mount-1.2.0/src/mount.rs:315:13
        |
    315 |             flags.bits(),
        |             ^^^^^^^^^^^^ expected u32, found u64
    
    error[E0308]: mismatched types
      --> .../sys-mount-1.2.0/src/mount.rs:20:22
       |
    20 |         const BIND = MS_BIND;
       |                      ^^^^^^^ expected u64, found u32
    
    error[E0308]: mismatched types
      --> .../sys-mount-1.2.0/src/mount.rs:24:25
       |
    24 |         const DIRSYNC = MS_DIRSYNC;
       |                         ^^^^^^^^^^ expected u64, found u32
    
    opened by codido 4
  • add ability to mount any file that contains a filesystem

    add ability to mount any file that contains a filesystem

    I'm writing a CSI plugin which, during testing, needs to mount files that contain a filesystem other then squashfs and ISO9660.

    I've made these changes that allow me to do so. Issuing the raw IOCTL even with mount flags set to empty (ie RW) is not sufficient as a follow-up ioclt (LOOP_SET_STATUS64) is needed.

    Let me know what you think,

    Thanks!

    opened by gila 4
  • Mount capabilities for unpriviledge users

    Mount capabilities for unpriviledge users

    Is it possible to use this library to somehow grant unpriviledge users the ability to mount arbitrary filesystems (not necessarily in fstab), similar to what pmount does?

    opened by dyamon 2
  • Please publish 1.2.2

    Please publish 1.2.2

    Can an owner of https://crates.io/crates/sys-mount please publish v1.2.2 in order to release commits https://github.com/pop-os/sys-mount/commit/e05b6a5c921a19b77cd66a93c9c481ff720b5921 and https://github.com/pop-os/sys-mount/commit/2c7a0ffa468d3493289a280c46e8f220b9ff6dc3 ?

    Thank you for merging those PRs so quickly by the way!

    opened by ophilli 2
  • Add ability to specify an offset for mounting loopback devices

    Add ability to specify an offset for mounting loopback devices

    I found that if you want to mount a loopback device with an offset it has to be specified when the loopback device is being attached. I added some option to do this and it seems to work well for my use case. I thought I'd submit it for consideration.

    opened by tsemczyszyn 1
  • CLI installing Issue

    CLI installing Issue

    npm i -g loopback-cli npm WARN deprecated [email protected]: See https://github.com/lydell/source-map-url#deprecated npm WARN deprecated [email protected]: Please see https://github.com/lydell/urix#deprecated npm WARN deprecated [email protected]: this library is no longer supported npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#deprecated npm WARN deprecated [email protected]: See https://github.com/lydell/source-map-resolve#deprecated npm WARN deprecated [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details. npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142 npm WARN deprecated [email protected]: This version is no longer supported, please upgrade to 3.x npm WARN deprecated [email protected]: core-js@<3.4 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js. npm ERR! code 127 npm ERR! path /root/.nvm/versions/node/v16.14.1/lib/node_modules/loopback-cli/node_modules/ejs npm ERR! command failed npm ERR! command sh -c node ./postinstall.js npm ERR! sh: node: command not found

    npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2022-04-16T13_37_29_408Z-debug-0.log

    opened by paramanandbalara 1
  • Please support returning the target path from a Mount

    Please support returning the target path from a Mount

    The Mount struct stores the target path internally. I'd love to have a target_path() method that returns it as a &Path, to avoid having to store it separately.

    opened by joshtriplett 1
  • Set read_only true if flags contains RDONLY

    Set read_only true if flags contains RDONLY

    When the file being mounted (bind mount) is on a read-only file system, the read_only flag must be set, otherwise an attempt is made to open the source file in RW mode, which results in an error.

    opened by matmoscicki 0
  • Please consider a

    Please consider a "loop" feature to make loopdev-related functions optional

    Would you consider adding a feature to make the loopdev-related functions optional, which would remove the dependency on the loopdev crate? This would be helpful for usage that only wants to mount non-loopback filesystems.

    opened by joshtriplett 0
  • Please consider supporting `findmount` alike interface

    Please consider supporting `findmount` alike interface

    Improvement request

    in the unix ecosystem a tool findmnt is available to filter infomation for mounted filesystems.

    It would be great to get an analogon implementation via sys-mount.

    Refernece

    https://github.com/karelzak/util-linux
    
    opened by rzerres 0
  • Consider setting up continuous integration to check pull requests against rustc 1.24.1

    Consider setting up continuous integration to check pull requests against rustc 1.24.1

    For example a minimal .travis.yml for this would be:

    language: rust
    rust: 1.24.1
    script: cargo check
    

    This would avoid the problem described in https://github.com/pop-os/sys-mount/pull/2#issuecomment-443554708 of pull requests breaking compatibility with rustc versions that need to be supported.

    opened by dtolnay 3
  • Support unmounting via the device path

    Support unmounting via the device path

    Currently, umount only supports unmounting by the target path where the device is mounted. Yet it should be capable of automatically discovering the target path associated with that device, and using that. This can be achieved through the use of our proc-mounts crate.

    enhancement good first issue bite-sized 
    opened by mmstick 0
Releases(1.0.2)
Owner
Pop!_OS
An Operating System by System76
Pop!_OS
Minty is an amazingly fast file deduplication app built in rust with a rust user interface.

minty Project Minty has a new look and feel!!! Minty is an amazingly fast file deduplication app built in rust with a rust user interface. I say super

null 26 Nov 20, 2022
ergonomic paths and files in rust

path_abs: ergonomic paths and files in rust. This library aims to provide ergonomic path and file operations to rust with reasonable performance. See

Rett Berg 45 Oct 29, 2022
Temporary directory management for Rust

tempdir A Rust library for creating a temporary directory and deleting its entire contents when the directory is dropped. Documentation Deprecation No

null 132 Jan 7, 2023
Temporary file library for rust

tempfile A secure, cross-platform, temporary file library for Rust. In addition to creating temporary files, this library also allows users to securel

Steven Allen 782 Dec 27, 2022
Extended attribute library for rust.

xattr A small library for setting, getting, and listing extended attributes. Supported Platforms: Linux, MacOS, FreeBSD, and NetBSD. API Documentation

Steven Allen 33 Nov 12, 2022
Rust implemention of Ascon

Ascon Pure Rust implementation of the lightweight Authenticated Encryption and Associated Data (AEAD) Ascon-128 and Ascon-128a. Security Notes This cr

Sebastian Ramacher 4 May 28, 2022
Lightweight Google Cloud Storage sync Rust Client with better performance than gsutil rsync

gcs-rsync Lightweight and efficient Rust gcs rsync for Google Cloud Storage. gcs-sync is faster than gsutil rsync when files change a lot while perfor

@cboudereau 4 Sep 8, 2022
A POSIX select I/O Multiplexing Rust library.

A POSIX select I/O Multiplexing Rust library.

b23r0 4 Jul 6, 2022
Supertag is a tag-based filesystem, written in Rust, for Linux and MacOS

Supertag is a tag-based filesystem, written in Rust, for Linux and MacOS. It provides a tag-based view of your files by removing the hierarchy constraints typically imposed on files and folders. In other words, it allows you to think about your files not as objects stored in folders, but as objects that can be filtered by folders.

Andrew Moffat 539 Dec 24, 2022
🦀 How to minimize Rust binary size 📦

Minimizing Rust Binary Size To help this project reach more users, consider upvoting the min-sized-rust Stack Overflow answer. This repository demonst

null 4.9k Jan 8, 2023
Spacedrive is an open source cross-platform file explorer, powered by a virtual distributed filesystem written in Rust.

Spacedrive A file explorer from the future. spacedrive.com » Download for macOS · Windows · Linux · iOS · watchOS · Android ~ Links will be added once

Spacedrive 16.2k Jan 7, 2023
shavee is a Program to automatically decrypt and mount ZFS datasets using Yubikey HMAC as 2FA or any USB drive with support for PAM to auto mount home directories.

shavee is a simple program to decrypt and mount encrypted ZFS user home directories at login using Yubikey HMAC or a Simple USB drive as 2FA written in rust.

Ashutosh Verma 38 Dec 24, 2022
Easy c̵̰͠r̵̛̠ö̴̪s̶̩̒s̵̭̀-t̶̲͝h̶̯̚r̵̺͐e̷̖̽ḁ̴̍d̶̖̔ ȓ̵͙ė̶͎ḟ̴͙e̸̖͛r̶̖͗ë̶̱́ṉ̵̒ĉ̷̥e̷͚̍ s̷̹͌h̷̲̉a̵̭͋r̷̫̊ḭ̵̊n̷̬͂g̵̦̃ f̶̻̊ơ̵̜ṟ̸̈́ R̵̞̋ù̵̺s̷̖̅ţ̸͗!̸̼͋

Rust S̵̓i̸̓n̵̉ I̴n̴f̶e̸r̵n̷a̴l mutability! Howdy, friendly Rust developer! Ever had a value get m̵̯̅ð̶͊v̴̮̾ê̴̼͘d away right under your nose just when

null 294 Dec 23, 2022
Rust-ffi-guide - A guide for doing FFI using Rust

Using unsafe for Fun and Profit A guide to traversing the FFI boundary between Rust and other languages. A rendered version is available here. This gu

Michael Bryan 261 Dec 1, 2022
libnotcurses-sys is a low-level Rust wrapper for the notcurses C library

libnotcurses-sys is a low-level Rust wrapper for the notcurses C library This library is built with several layers of zero-overhead abstractions over

nick black 29 Nov 26, 2022
A safe Rust FFI binding for the NVIDIA® Tools Extension SDK (NVTX).

NVIDIA® Tools Extension SDK (NVTX) is a C-based Application Programming Interface (API) for annotating events, code ranges, and resources in your applications. Official documentation for NVIDIA®'s NVTX can be found here.

Spencer Imbleau 78 Jan 2, 2023
Rust Attribute-Based Encryption library rabe's C FFI binding , support CP-ABE and KP-ABE encrypt and decrypt, submodule of Rabe.Core c# library.

Rabe-ffi Rust Attribute-Based Encryption library rabe's C FFI binding , support CP-ABE and KP-ABE encrypt and decrypt, submodule of Rabe.Core c# libra

Aya0wind 2 Oct 10, 2022
Rust Imaging Library's Python binding: A performant and high-level image processing library for Python written in Rust

ril-py Rust Imaging Library for Python: Python bindings for ril, a performant and high-level image processing library written in Rust. What's this? Th

Cryptex 13 Dec 6, 2022
High-level memory-safe binding generator for Flutter/Dart <-> Rust

flutter_rust_bridge: High-level memory-safe binding generator for Flutter/Dart <-> Rust Want to combine the best between Flutter, a cross-platform hot

fzyzcjy 2.1k Dec 31, 2022