Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.x86_64-unknown-linux-gnu]
runner = '.cargo/runner-x86_64-unknown-linux-gnu'
5 changes: 5 additions & 0 deletions .cargo/runner-x86_64-unknown-linux-gnu
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

binary_name=`basename $1`

sudo -E --preserve-env=PATH $@
64 changes: 64 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
on: [push, pull_request]

name: Continuous integration

jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: check

test:
name: Test Suite
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: test

fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add clippy
- uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ travis-ci = { repository = "serde-rs/serde" }
errno = "0.2"
libc = "0.2"

[build-dependencies]
bindgen = "0.58.1"

[dev-dependencies]
tempfile = "3.1.0"
lazy_static = "1.3.0"
Expand Down
18 changes: 18 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
extern crate bindgen;

use bindgen::Builder;
use std::{env::var, path::PathBuf};

fn main() {
let bindings = Builder::default()
.header_contents("wrapper.h", "#include <linux/loop.h>")
.derive_default(true)
.generate()
.expect("Could not generate bindings");

let mut bindings_path = PathBuf::from(var("OUT_DIR").unwrap());
bindings_path.push("bindings.rs");
bindings
.write_to_file(&bindings_path)
.expect("Could not write bindings to file");
}
28 changes: 20 additions & 8 deletions losetup/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
extern crate clap;
extern crate loopdev;

use loopdev::{LoopControl, LoopDevice};
use std::io::{self, Write};
use std::process::exit;
use loopdev::{LoopControl, LoopDevice};

fn find() -> io::Result<()> {
let loopdev = LoopControl::open()?.next_free()?;
Expand All @@ -13,16 +13,25 @@ fn find() -> io::Result<()> {
}

fn attach(matches: &clap::ArgMatches) -> io::Result<()> {
let quite = matches.is_present("quite");
let quiet = matches.is_present("quiet");
let image = matches.value_of("image").unwrap();
let offset = value_t!(matches.value_of("offset"), u64).unwrap_or(0);
let sizelimit = value_t!(matches.value_of("sizelimit"), u64).unwrap_or(0);
let loopdev = match matches.value_of("loopdev") {
let size_limit = value_t!(matches.value_of("sizelimit"), u64).unwrap_or(0);
let read_only = matches.is_present("read-only");
let autoclear = matches.is_present("autoclear");
let mut loopdev = match matches.value_of("loopdev") {
Some(loopdev) => LoopDevice::open(&loopdev)?,
None => LoopControl::open().and_then(|lc| lc.next_free())?,
};
loopdev.attach_with_sizelimit(&image, offset, sizelimit)?;
if !quite {
loopdev
.with()
.offset(offset)
.size_limit(size_limit)
.read_only(read_only)
.autoclear(autoclear)
.attach(image)?;

if !quiet {
println!("{}", loopdev.path().unwrap().display());
}
Ok(())
Expand Down Expand Up @@ -60,7 +69,9 @@ fn main() {
(@arg loopdev: "the loop device to attach")
(@arg offset: -o --offset +takes_value "the offset within the file to start at")
(@arg sizelimit: -s --sizelimit +takes_value "the file is limited to this size")
(@arg quite: -q --quite "don't print the device name")
(@arg read_only: -r --read-only "set up a read-only loop device")
(@arg autoclear: -a --autoclear "set the autoclear flag")
(@arg quiet: -q --quiet "don't print the device name")
)
(@subcommand detach =>
(about: "detach the loop device from the backing file")
Expand All @@ -75,7 +86,8 @@ fn main() {
(@arg free: -f --free "find free devices")
(@arg used: -u --used "find used devices")
)
).get_matches();
)
.get_matches();

let result = match matches.subcommand() {
("find", _) => find(),
Expand Down
Loading