Crates.io | loopdev-fyra |
lib.rs | loopdev-fyra |
version | 0.5.0 |
source | src |
created_at | 2023-10-22 13:55:24.666656 |
updated_at | 2023-10-22 13:55:24.666656 |
description | Setup and control loop devices |
homepage | |
repository | https://github.com/FyraLabs/loopdev |
max_upload_size | |
id | 1010597 |
size | 35,730 |
Setup and control loop devices.
Provides rust interface with similar functionality to the Linux utility losetup
.
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();
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.