diff --git a/Cargo.lock b/Cargo.lock index 47ad5f6..b746ac2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -40,7 +40,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ "hermit-abi", "libc", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -114,6 +114,18 @@ dependencies = [ "generic-array", ] +[[package]] +name = "build_const" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ae4235e6dac0694637c763029ecea1a2ec9e4e06ec2729bd21ba4d9c863eb7" + +[[package]] +name = "byteorder" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" + [[package]] name = "byteorder" version = "1.4.3" @@ -128,7 +140,7 @@ checksum = "f5531982124b31420dc41d0c8c0abbdd03e97d561dfb2af027b9140ee2b1f50c" dependencies = [ "anyhow", "binread", - "byteorder", + "byteorder 1.4.3", "candid_derive", "codespan-reporting", "hex", @@ -175,7 +187,7 @@ dependencies = [ "num-integer", "num-traits", "time 0.1.43", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -197,6 +209,15 @@ dependencies = [ "libc", ] +[[package]] +name = "crc" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d663548de7f5cca343f1e0a48d14dcfb0e9eb4e079ec58883b7251539fa10aeb" +dependencies = [ + "build_const", +] + [[package]] name = "crc32fast" version = "1.3.2" @@ -245,7 +266,7 @@ checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" dependencies = [ "libc", "redox_users", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -263,6 +284,30 @@ dependencies = [ "log", ] +[[package]] +name = "ext4" +version = "0.9.0" +source = "git+https://github.com/FauxFaux/ext4-rs?rev=1858f9d11ba3454f5a274275e059f631fb7a3b01#1858f9d11ba3454f5a274275e059f631fb7a3b01" +dependencies = [ + "anyhow", + "bitflags", + "byteorder 1.4.3", + "crc", + "positioned-io", + "thiserror", +] + +[[package]] +name = "ext4-example" +version = "0.1.0" +dependencies = [ + "ext4", + "ic-cdk 0.4.0", + "ic-cdk-macros", + "icfs", + "icfs-ext4", +] + [[package]] name = "fatfs" version = "0.4.0" @@ -415,6 +460,16 @@ dependencies = [ "icfs", ] +[[package]] +name = "icfs-ext4" +version = "0.1.0" +dependencies = [ + "ext4", + "ic-cdk 0.4.0", + "icfs", + "positioned-io", +] + [[package]] name = "icfs-fatfs" version = "0.1.0" @@ -452,6 +507,16 @@ dependencies = [ "either", ] +[[package]] +name = "kernel32-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +dependencies = [ + "winapi 0.2.8", + "winapi-build", +] + [[package]] name = "lalrpop" version = "0.19.7" @@ -644,7 +709,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -678,6 +743,18 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db8bcd96cb740d03149cbad5518db9fd87126a10ab519c011893b1754134c468" +[[package]] +name = "positioned-io" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c405a565f48a728dbb07fa1770e30791b0fa3e6344c1e5615225ce84049354d6" +dependencies = [ + "byteorder 0.5.3", + "kernel32-sys", + "libc", + "winapi 0.2.8", +] + [[package]] name = "precomputed-hash" version = "0.1.1" @@ -867,7 +944,7 @@ checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" dependencies = [ "dirs-next", "rustversion", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -906,7 +983,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" dependencies = [ "libc", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -979,6 +1056,12 @@ version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +[[package]] +name = "winapi" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" + [[package]] name = "winapi" version = "0.3.9" @@ -989,6 +1072,12 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] +[[package]] +name = "winapi-build" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" + [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -1001,7 +1090,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 8c6a692..5faab9b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,9 @@ [workspace] members = [ "crates/icfs", + "crates/icfs-ext4", "crates/icfs-fatfs", "examples/icfs", + "examples/ext4", "examples/fatfs", ] diff --git a/crates/icfs-ext4/Cargo.toml b/crates/icfs-ext4/Cargo.toml new file mode 100644 index 0000000..3b8c6e6 --- /dev/null +++ b/crates/icfs-ext4/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "icfs-ext4" +version = "0.1.0" +edition = "2018" +authors = ["Paul Young <84700+paulyoung@users.noreply.github.com>"] + +[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" \ No newline at end of file diff --git a/crates/icfs-ext4/lib.rs b/crates/icfs-ext4/lib.rs new file mode 100644 index 0000000..3796d23 --- /dev/null +++ b/crates/icfs-ext4/lib.rs @@ -0,0 +1,3 @@ +impl positioned_io::ReadAt for icfs::StableMemory { + +} diff --git a/crates/icfs-fatfs/Cargo.toml b/crates/icfs-fatfs/Cargo.toml index f9736bc..2dd9c17 100644 --- a/crates/icfs-fatfs/Cargo.toml +++ b/crates/icfs-fatfs/Cargo.toml @@ -4,8 +4,6 @@ version = "0.1.0" edition = "2018" authors = ["Paul Young <84700+paulyoung@users.noreply.github.com>"] -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [lib] path = "lib.rs" crate-type = ["cdylib", "lib"] diff --git a/dfx.json b/dfx.json index e3bab0d..a09f87c 100644 --- a/dfx.json +++ b/dfx.json @@ -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'", diff --git a/examples/ext4/Cargo.toml b/examples/ext4/Cargo.toml new file mode 100644 index 0000000..3120b89 --- /dev/null +++ b/examples/ext4/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "ext4-example" +version = "0.1.0" +edition = "2018" +authors = ["Paul Young <84700+paulyoung@users.noreply.github.com>"] + +[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" } \ No newline at end of file diff --git a/examples/ext4/ext4.did b/examples/ext4/ext4.did new file mode 100644 index 0000000..6f125fd --- /dev/null +++ b/examples/ext4/ext4.did @@ -0,0 +1,5 @@ +service : { + ls : () -> (vec text) query; + write_file : (filename : text, contents : text) -> (); + read_file : (filename : text) -> (text) query; +} \ No newline at end of file diff --git a/examples/ext4/lib.rs b/examples/ext4/lib.rs new file mode 100644 index 0000000..15a696a --- /dev/null +++ b/examples/ext4/lib.rs @@ -0,0 +1,58 @@ +use ic_cdk_macros::{query, update}; + +thread_local! { + static STABLE_MEMORY: std::cell::RefCell + = std::cell::RefCell::new(icfs::StableMemory::default()); + + static VOL: std::cell::RefCell> = { + let vol: Result> = 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 { + _ls().unwrap() +} + +fn _ls() -> std::io::Result> { + Ok(vec!("FIXME".to_string())) +} + +#[query] +fn read_file(filename: String) -> String { + _read_file(filename).unwrap() +} + +fn _read_file(filename: String) -> std::io::Result { + 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(()) +} diff --git a/examples/ext4/test.ic-repl b/examples/ext4/test.ic-repl new file mode 100644 index 0000000..4655632 --- /dev/null +++ b/examples/ext4/test.ic-repl @@ -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!"; diff --git a/examples/fatfs/Cargo.toml b/examples/fatfs/Cargo.toml index df1125c..e03f548 100644 --- a/examples/fatfs/Cargo.toml +++ b/examples/fatfs/Cargo.toml @@ -4,8 +4,6 @@ version = "0.1.0" edition = "2018" authors = ["Paul Young <84700+paulyoung@users.noreply.github.com>"] -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [lib] path = "lib.rs" crate-type = ["cdylib", "lib"] diff --git a/flake.nix b/flake.nix index 81fadc1..7f62aec 100644 --- a/flake.nix +++ b/flake.nix @@ -145,9 +145,11 @@ darwinPackages = { icfs = buildLocalRustPackage "icfs"; + icfs-ext4 = buildLocalRustPackage "icfs-ext4"; icfs-fatfs = buildLocalRustPackage "icfs-fatfs"; icfs-example = buildLocalRustPackage "icfs-example"; + ext4-example = buildLocalRustPackage "ext4-example"; fatfs-example = buildLocalRustPackage "fatfs-example"; }; in @@ -161,6 +163,7 @@ packages = darwinPackages // pkgs.lib.optionalAttrs pkgs.stdenv.isDarwin { icfs-example-test = buildExampleTest "icfs" packages.icfs-example; + ext4-example-test = buildExampleTest "ext4" packages.ext4-example; fatfs-example-test = buildExampleTest "fatfs" packages.fatfs-example; };