A rust library to setup and control loopback devices
Find a file
Michael Daffin b063c2baa0 Fixes example test and makes attach_with_loop_info consume the loop_info64 struct
Even though it is passed by reference to the ioctl conceptually the it should be created and consumed once per call to a attach function.
History 2021-03-30 23:53:57 +00:00
losetup Adds support for set_capacity ioctl 2017-12-20 17:06:10 +00:00
src Fixes example test and makes attach_with_loop_info consume the loop_info64 struct 2021-03-30 23:53:57 +00:00
tests Adds tests for detach 2019-08-11 11:38:03 +00:00
.gitignore chore(vagrant): Adds a vagrant file 2018-08-15 11:50:17 +01:00
.travis-deploy chore(ci): Adds a automated publish to crates.io 2018-10-04 10:41:27 +01:00
.travis.yml Adds inital intergration tests for attach 2019-08-10 18:14:04 +00:00
Cargo.toml Adds inital intergration tests for attach 2019-08-10 18:14:04 +00:00
LICENSE Adds some needed files 2016-05-20 23:33:08 +01:00
README.md Spelling fixes for README.md and comments 2018-10-13 20:52:35 -07:00
Vagrantfile Add cmd to install gcc on Vagrantfile in order to build libc crate 2019-08-07 18:00:52 +00: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("test.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.