Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
WolverinDEV committed Dec 30, 2023
2 parents 113bb0d + 20b829d commit 3b496b0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion windows-projfs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "windows-projfs"
version = "0.1.5"
version = "0.1.6"
edition = "2021"
authors = ["M. Hadenfeldt <[email protected]>"]
description = "A rust library for the Windows projected file system API"
Expand Down
31 changes: 21 additions & 10 deletions windows-projfs/src/aligned_buffer.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
use std::ffi::c_void;

use windows::Win32::Storage::ProjectedFileSystem::{
PrjAllocateAlignedBuffer,
PrjFreeAlignedBuffer,
PRJ_NAMESPACE_VIRTUALIZATION_CONTEXT,
use std::{
ffi::c_void,
sync::Arc,
};

use windows::Win32::Storage::ProjectedFileSystem::PRJ_NAMESPACE_VIRTUALIZATION_CONTEXT;

use crate::library::ProjectedFSLibrary;

pub struct PrjAlignedBuffer {
library: Arc<dyn ProjectedFSLibrary>,

length: usize,
raw_buffer: *mut c_void,
}

impl PrjAlignedBuffer {
pub fn allocate(context: PRJ_NAMESPACE_VIRTUALIZATION_CONTEXT, length: usize) -> Option<Self> {
let raw_buffer = unsafe { PrjAllocateAlignedBuffer(context, length) };
pub fn allocate(
library: Arc<dyn ProjectedFSLibrary>,
context: PRJ_NAMESPACE_VIRTUALIZATION_CONTEXT,
length: usize,
) -> Option<Self> {
let raw_buffer = unsafe { library.prj_allocate_aligned_buffer(context, length) };
if raw_buffer.is_null() {
None
} else {
Some(Self { length, raw_buffer })
Some(Self {
library,
length,
raw_buffer,
})
}
}

Expand All @@ -28,6 +39,6 @@ impl PrjAlignedBuffer {

impl Drop for PrjAlignedBuffer {
fn drop(&mut self) {
unsafe { PrjFreeAlignedBuffer(self.raw_buffer) };
unsafe { self.library.prj_free_aligned_buffer(self.raw_buffer) };
}
}
1 change: 1 addition & 0 deletions windows-projfs/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ mod native {
};

let mut buffer = PrjAlignedBuffer::allocate(
context.library.clone(),
callback_data.namespace_virtualization_context,
chunk_length,
)
Expand Down

0 comments on commit 3b496b0

Please sign in to comment.