Skip to content
Snippets Groups Projects
Verified Commit e538d53f authored by Jeremy Soller's avatar Jeremy Soller
Browse files

0.2.8 - Use redoxfs library to archive, add free space to image

parent 92149215
No related branches found
Tags 0.2.19
No related merge requests found
......@@ -668,7 +668,7 @@ dependencies = [
"liner 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_pkgutils 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"redoxfs 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"redoxfs 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.94 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.94 (registry+https://github.com/rust-lang/crates.io-index)",
"termion 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -723,18 +723,20 @@ dependencies = [
[[package]]
name = "redoxer"
version = "0.2.7"
version = "0.2.8"
dependencies = [
"dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-mounts 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_installer 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)",
"redoxfs 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"toml 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "redoxfs"
version = "0.3.4"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"fuse 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -1187,7 +1189,7 @@ dependencies = [
"checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
"checksum redox_users 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3fe5204c3a17e97dde73f285d49be585df59ed84b50a872baf416e73b62c3828"
"checksum redoxfs 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4d5b94177303e4c07b8da7f90fb86c1d194630dc08c2676aa866be1d25892783"
"checksum redoxfs 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "801d7b3f9ba3f5a68fb1738545ea074cf2f6361e7f4cbf4133a5ecf6086f6ded"
"checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e"
"checksum ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2c4db68a2e35f3497146b7e4563df7d4773a2433230c5e4b448328e31740458a"
"checksum rle-decode-fast 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cabe4fa914dec5870285fa7f71f602645da47c486e68486d2b4ceb4a343e90ac"
......
[package]
name = "redoxer"
version = "0.2.7"
version = "0.2.8"
description = "Method for quickly running programs inside of Redox from a KVM capable OS."
license = "MIT"
authors = ["Jeremy Soller <jackpot51@gmail.com>"]
......@@ -10,6 +10,8 @@ edition = "2018"
[dependencies]
dirs = "1.0"
redox_installer = "0.2"
redox_syscall = "0.1"
redoxfs = "0.3.6"
tempfile = "3.0"
toml = "0.5"
......
......@@ -16,9 +16,6 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \
# Set path
ENV PATH=/root/.cargo/bin:$PATH
# Install redoxfs
RUN cargo install redoxfs
# Install redoxer
COPY . /root/redoxer
RUN cargo install --path /root/redoxer
......
use redoxfs::{archive_at, BLOCK_SIZE, DiskSparse, FileSystem};
use std::{env, fs, io};
use std::io::{Seek, Write};
use std::path::{Path, PathBuf};
use std::process::{self, Command};
use std::time::{SystemTime, UNIX_EPOCH};
use crate::{installed, redoxer_dir, status_error};
use crate::{installed, redoxer_dir, status_error, syscall_error};
use crate::redoxfs::RedoxFs;
static BASE_TOML: &'static str = include_str!("../res/base.toml");
......@@ -110,13 +112,40 @@ fn base(bootloader_bin: &Path, gui: bool, fuse: bool) -> io::Result<PathBuf> {
Ok(base_bin)
}
fn inner(arguments: &[String], folder_opt: Option<String>, gui: bool) -> io::Result<i32> {
let fuse = Path::new("/dev/fuse").exists();
if ! fuse && ! installed("tar")? {
eprintln!("redoxer: tar not found, please install before continuing");
process::exit(1);
}
fn archive_free_space(disk_path: &Path, folder_path: &Path, bootloader_path: &Path, free_space: u64) -> io::Result<()> {
let disk = DiskSparse::create(&disk_path).map_err(syscall_error)?;
let bootloader = fs::read(bootloader_path)?;
let ctime = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
let mut fs = FileSystem::create_reserved(
disk,
&bootloader,
ctime.as_secs(),
ctime.subsec_nanos()
).map_err(syscall_error)?;
let root_block = fs.header.1.root;
archive_at(&mut fs, folder_path, root_block)?;
let free_block = fs.header.1.free;
let mut free = fs.node(free_block).map_err(syscall_error)?;
let end_block = free.1.extents[0].block;
free.1.extents[0].length = free_space;
let end_size = end_block * BLOCK_SIZE + free.1.extents[0].length;
fs.write_at(free.0, &free.1).map_err(syscall_error)?;
fs.header.1.size = end_size;
let header = fs.header;
fs.write_at(header.0, &header.1).map_err(syscall_error)?;
let size = header.0 * BLOCK_SIZE + end_size;
fs.disk.file.set_len(size)?;
Ok(())
}
fn inner(arguments: &[String], folder_opt: Option<String>, gui: bool) -> io::Result<i32> {
let kvm = Path::new("/dev/kvm").exists();
if ! installed("qemu-system-x86_64")? {
......@@ -124,7 +153,12 @@ fn inner(arguments: &[String], folder_opt: Option<String>, gui: bool) -> io::Res
process::exit(1);
}
if ! installed("redoxfs")? {
let fuse = Path::new("/dev/fuse").exists();
if ! fuse && ! installed("tar")? {
eprintln!("redoxer: tar not found, please install before continuing");
process::exit(1);
}
if fuse && ! installed("redoxfs")? {
eprintln!("redoxer: redoxfs not found, installing with cargo");
Command::new("cargo")
.arg("install")
......@@ -212,12 +246,12 @@ fn inner(arguments: &[String], folder_opt: Option<String>, gui: bool) -> io::Res
}
if ! fuse {
Command::new("redoxfs-ar")
.arg(&redoxer_bin)
.arg(&redoxer_dir)
.arg(&bootloader_bin)
.status()
.and_then(status_error)?;
archive_free_space(
&redoxer_bin,
&redoxer_dir,
&bootloader_bin,
1024 * 1024 * 1024
)?;
}
// Set default bootloader configuration
......
......@@ -44,6 +44,10 @@ fn status_error(status: process::ExitStatus) -> io::Result<()> {
}
}
fn syscall_error(err: syscall::Error) -> io::Error {
io::Error::from_raw_os_error(err.errno)
}
fn usage() {
eprintln!("redoxer bench - cargo bench with Redox target in Redox VM");
eprintln!("redoxer build - cargo build with Redox target");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment