Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ext4 #18

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

ext4 #18

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
105 changes: 97 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[workspace]
members = [
"crates/icfs",
"crates/icfs-ext4",
"crates/icfs-fatfs",
"examples/icfs",
"examples/ext4",
"examples/fatfs",
]
15 changes: 15 additions & 0 deletions crates/icfs-ext4/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "icfs-ext4"
version = "0.1.0"
edition = "2018"
authors = ["Paul Young <[email protected]>"]

[lib]
path = "lib.rs"
crate-type = ["cdylib", "lib"]

[dependencies]
ext4 = { git = "https://github.com/FauxFaux/ext4-rs", rev = "1858f9d11ba3454f5a274275e059f631fb7a3b01" }
ic-cdk = { git = "https://github.com/dfinity/cdk-rs.git", rev = "a253119adb08929b6304d007ee0a6a37960656ed" }
icfs = { path = "../../crates/icfs" }
positioned-io = "0.2"
3 changes: 3 additions & 0 deletions crates/icfs-ext4/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
impl positioned_io::ReadAt for icfs::StableMemory {

}
2 changes: 0 additions & 2 deletions crates/icfs-fatfs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ version = "0.1.0"
edition = "2018"
authors = ["Paul Young <[email protected]>"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
path = "lib.rs"
crate-type = ["cdylib", "lib"]
Expand Down
6 changes: 6 additions & 0 deletions dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
"candid": "examples/icfs/icfs.did",
"wasm": "result/lib/icfs_example.wasm"
},
"ext4": {
"type": "custom",
"build": "nix build '.#ext4-example'",
"candid": "examples/ext4/ext4.did",
"wasm": "result/lib/ext4_example.wasm"
},
"fatfs": {
"type": "custom",
"build": "nix build '.#fatfs-example'",
Expand Down
16 changes: 16 additions & 0 deletions examples/ext4/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "ext4-example"
version = "0.1.0"
edition = "2018"
authors = ["Paul Young <[email protected]>"]

[lib]
path = "lib.rs"
crate-type = ["cdylib", "lib"]

[dependencies]
ext4 = { git = "https://github.com/FauxFaux/ext4-rs", rev = "1858f9d11ba3454f5a274275e059f631fb7a3b01" }
ic-cdk = { git = "https://github.com/dfinity/cdk-rs.git", rev = "a253119adb08929b6304d007ee0a6a37960656ed" }
ic-cdk-macros = "0.3"
icfs = { path = "../../crates/icfs" }
icfs-ext4 = { path = "../../crates/icfs-ext4" }
5 changes: 5 additions & 0 deletions examples/ext4/ext4.did
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
service : {
ls : () -> (vec text) query;
write_file : (filename : text, contents : text) -> ();
read_file : (filename : text) -> (text) query;
}
58 changes: 58 additions & 0 deletions examples/ext4/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use ic_cdk_macros::{query, update};

thread_local! {
static STABLE_MEMORY: std::cell::RefCell<icfs::StableMemory>
= std::cell::RefCell::new(icfs::StableMemory::default());

static VOL: std::cell::RefCell<ext4::SuperBlock<icfs::StableMemory>> = {
let vol: Result<ext4::SuperBlock<icfs::StableMemory>> = STABLE_MEMORY.with(|stable_memory| {
let stable_memory = *stable_memory.borrow();

#[cfg(target_arch = "wasm32")]
let memory_pages = core::arch::wasm32::memory_size(0)
.try_into()
.map_err(|error| std::io::Error::new(std::io::ErrorKind::Other, error))?;

#[cfg(not(target_arch = "wasm32"))]
let memory_pages = 19;

icfs::StableMemory::grow(memory_pages)?;

let mut options = ext4::Options::default();
options.checksums = ext4::Checksums::Enabled;

let vol = ext4::SuperBlock::new_with_options(stable_memory, &options).expect("ext4 volume");

Ok(vol)
});

std::cell::RefCell::new(vol.unwrap())
}
}

#[query]
fn ls() -> Vec<String> {
_ls().unwrap()
}

fn _ls() -> std::io::Result<Vec<String>> {
Ok(vec!("FIXME".to_string()))
}

#[query]
fn read_file(filename: String) -> String {
_read_file(filename).unwrap()
}

fn _read_file(filename: String) -> std::io::Result<String> {
Ok("FIXME".to_string())
}

#[update]
fn write_file(filename: String, contents: String) {
_write_file(filename, contents).unwrap();
}

fn _write_file(filename: String, contents: String) -> std::io::Result<()> {
Ok(())
}
29 changes: 29 additions & 0 deletions examples/ext4/test.ic-repl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import ext4 = "rrkah-fqaaa-aaaaa-aaaaq-cai" as "ext4.did";
// import ext4 = "ai7t5-aibaq-aaaaa-aaaaa-c" as "ext4.did";

let result = call ext4.ls();
assert result == vec {};

let result = call ext4.write_file("hello.txt", "Hello, World!");
assert result == null;

let result = call ext4.ls();
assert result == vec { "hello.txt"; };

let result = call ext4.read_file("hello.txt");
assert result == "Hello, World!";

let result = call ext4.write_file("hello.txt", "Hello!");
assert result == null;

let result = call ext4.read_file("hello.txt");
assert result == "Hello!";

let result = call ext4.write_file("goodbye.txt", "Goodbye!");
assert result == null;

let result = call ext4.ls();
assert result == vec { "hello.txt"; "goodbye.txt"; };

let result = call ext4.read_file("goodbye.txt");
assert result == "Goodbye!";
2 changes: 0 additions & 2 deletions examples/fatfs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ version = "0.1.0"
edition = "2018"
authors = ["Paul Young <[email protected]>"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
path = "lib.rs"
crate-type = ["cdylib", "lib"]
Expand Down
Loading