From bd11a539479a7333f197a246039e8bcf7fdf5085 Mon Sep 17 00:00:00 2001 From: Avril Date: Wed, 3 Mar 2021 17:43:24 +0000 Subject: [PATCH] memmap un/shuffle skel --- shuffle3rs/Cargo.lock | 33 +++++++++++++++++++++++++++++++++ shuffle3rs/Cargo.toml | 1 + shuffle3rs/src/proc.rs | 26 ++++++++++++++++++++++++-- 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/shuffle3rs/Cargo.lock b/shuffle3rs/Cargo.lock index 05206a0..a95e467 100644 --- a/shuffle3rs/Cargo.lock +++ b/shuffle3rs/Cargo.lock @@ -31,6 +31,16 @@ version = "0.2.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c" +[[package]] +name = "memmap" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "ppv-lite86" version = "0.2.10" @@ -83,6 +93,7 @@ version = "0.1.0" dependencies = [ "cfg-if", "lazy_static", + "memmap", "rand", "rand_chacha", "smallvec", @@ -99,3 +110,25 @@ name = "wasi" version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/shuffle3rs/Cargo.toml b/shuffle3rs/Cargo.toml index 8beee66..762a530 100644 --- a/shuffle3rs/Cargo.toml +++ b/shuffle3rs/Cargo.toml @@ -29,6 +29,7 @@ deferred-drop = [] [dependencies] cfg-if = "1.0.0" lazy_static = "1.4.0" +memmap = "0.7.0" rand = "0.8.3" smallvec = {version = "1.6.1", features=["union"]} diff --git a/shuffle3rs/src/proc.rs b/shuffle3rs/src/proc.rs index 05602ce..9eca902 100644 --- a/shuffle3rs/src/proc.rs +++ b/shuffle3rs/src/proc.rs @@ -2,6 +2,9 @@ use super::*; use std::path::{Path, PathBuf}; use std::io; +use std::fs; + +use memmap::MmapMut; /// What kind of operation are we doing? #[derive(Debug, Clone, PartialEq, Eq, Hash, Copy)] @@ -11,14 +14,33 @@ pub enum ModeKind Unshuffle } +fn load_file_ip(file: impl AsRef) -> io::Result +{ + let file = fs::OpenOptions::new() + .read(true) + .write(true) + .open(file)?; + Ok(unsafe { + MmapMut::map_mut(&file)? + }) +} + pub fn shuffle_file_ip(file: impl AsRef) -> io::Result<()> { - todo!() + let mut file = load_file_ip(file)?; + todo!("shuffling"); + file.flush()?; + + Ok(()) } pub fn unshuffle_file_ip(file: impl AsRef) -> io::Result<()> { - todo!() + let mut file = load_file_ip(file)?; + todo!("unshuffling"); + file.flush()?; + + Ok(()) } /// Process these files in place with this mode