[io_engine] Add Block::zeroed() constructor

This commit is contained in:
Joe Thornber 2021-02-09 14:34:26 +00:00
parent c3c6d37aea
commit 763b2d14b2
4 changed files with 16 additions and 0 deletions

7
Cargo.lock generated
View File

@ -671,6 +671,12 @@ version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
[[package]]
name = "safemem"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072"
[[package]]
name = "shared_child"
version = "0.3.4"
@ -798,6 +804,7 @@ dependencies = [
"quickcheck",
"quickcheck_macros",
"rand",
"safemem",
"tempfile",
"termion",
"thiserror",

View File

@ -27,6 +27,7 @@ num-derive = "0.3"
num-traits = "0.2"
quick-xml = "0.18"
rand = "0.7"
safemem = "0.3.3"
tempfile = "3.1"
threadpool = "1.8"
thiserror = "1.0"

View File

@ -1,5 +1,6 @@
use io_uring::opcode::{self, types};
use io_uring::IoUring;
use safemem::write_bytes;
use std::alloc::{alloc, dealloc, Layout};
use std::fs::File;
use std::fs::OpenOptions;
@ -32,6 +33,12 @@ impl Block {
Block { loc, data: ptr }
}
pub fn zeroed(loc: u64) -> Block {
let r = Self::new(loc);
write_bytes(r.get_data(), 0);
r
}
pub fn get_data<'a>(&self) -> &'a mut [u8] {
unsafe { std::slice::from_raw_parts_mut::<'a>(self.data, BLOCK_SIZE) }
}

View File

@ -95,6 +95,7 @@ impl Report {
//------------------------------------------
#[allow(dead_code)]
struct PBInner {
title: String,
bar: ProgressBar,