A rust library to setup and control loopback devices
Find a file
Josh Triplett 7efea6b311
Disable most features of bindgen to reduce dependencies (#41)
By default, bindgen depends on everything needed to build the bindgen
command-line tool, such as clap and its various dependencies. Disable
default-features on bindgen and just enable the minimum required
features. This reduces loopdev's full dependency tree from 54 crates to
39 crates.
History 2021-08-09 15:38:18 +01:00
losetup Add read_only, autoclear and direct IO 2021-06-01 09:51:55 +01:00
src Removes deprecated methods (#40) 2021-07-02 18:26:22 +00:00
tests Use bindgen to generate loopdev bindings 2021-05-31 11:40:36 +01:00
.gitignore Updates documentation to use disk.img instead of test.img and adds an extra module example with the options 2021-06-01 10:45:06 +01:00
.travis-deploy chore(ci): Adds a automated publish to crates.io 2018-10-04 10:41:27 +01:00
.travis.yml Puts direct_io support behind a feature flag (#39) 2021-06-29 00:15:18 +00:00
build.rs Use bindgen to generate loopdev bindings 2021-05-31 11:40:36 +01:00
Cargo.toml Disable most features of bindgen to reduce dependencies (#41) 2021-08-09 15:38:18 +01:00
LICENSE Adds some needed files 2016-05-20 23:33:08 +01:00
README.md Updates documentation to use disk.img instead of test.img and adds an extra module example with the options 2021-06-01 10:45:06 +01:00
Vagrantfile Updates documentation to use disk.img instead of test.img and adds an extra module example with the options 2021-06-01 10:45:06 +01:00

Build Status crates.io

loopdev

Setup and control loop devices.

Provides rust interface with similar functionality to the Linux utility losetup.

Documentation

Examples

use loopdev::LoopControl;
let lc = LoopControl::open().unwrap();
let ld = lc.next_free().unwrap();

println!("{}", ld.path().unwrap().display());

ld.attach_file("disk.img").unwrap();
// ...
ld.detach().unwrap();

Development

Running The Tests Locally

Unfortunately the tests require root only syscalls and thus must be run as root. There is little point in mocking out these syscalls as I want to test they actually function as expected and if they were to be mocked out then the tests would not really be testing anything useful.

A vagrant file is provided that can be used to create an environment to safely run these tests locally as root. With Vagrant and VirtualBox installed you can do the following to run the tests.

vagrant up
vagrant ssh
sudo -i
cd /vagrant
cargo test

Note that the tests are built with root privileges, but since vagrant maps this directory back to the host as your normal user there is minimal issues with this. At worst the vagrant box will become trashed and can be rebuilt in minutes.