Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
touilleMan committed Aug 7, 2024
1 parent ffae772 commit 4bc7cd7
Showing 1 changed file with 64 additions and 16 deletions.
80 changes: 64 additions & 16 deletions winfsp_wrs/src/callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,12 @@ impl TrampolineInterface {
) -> NTSTATUS {
let fs = &*(*file_system).UserContext.cast::<C>();
let fctx = C::FileContext::access(file_context);
let buffer = std::slice::from_raw_parts_mut(buffer.cast(), length as usize);
let buffer = if !buffer.is_null() {
std::slice::from_raw_parts_mut(buffer.cast(), length as usize)
} else {
&mut []

Check warning on line 709 in winfsp_wrs/src/callback.rs

View workflow job for this annotation

GitHub Actions / ci

Diff in \\?\D:\a\winfsp_wrs\winfsp_wrs\winfsp_wrs\src\callback.rs

Check warning on line 709 in winfsp_wrs/src/callback.rs

View workflow job for this annotation

GitHub Actions / ci

Diff in \\?\D:\a\winfsp_wrs\winfsp_wrs\winfsp_wrs\src\callback.rs
};


match C::read(fs, fctx, buffer, offset) {
Ok(bytes_transferred) => {
Expand Down Expand Up @@ -742,7 +747,11 @@ impl TrampolineInterface {
) -> NTSTATUS {
let fs = &*(*file_system).UserContext.cast::<C>();
let fctx = C::FileContext::access(file_context);
let buffer = std::slice::from_raw_parts(buffer.cast(), length as usize);
let buffer = if !buffer.is_null() {
std::slice::from_raw_parts(buffer.cast(), length as usize)
} else {
&[]
};

let mode = match (write_to_end_of_file != 0, constrained_io != 0) {
(false, false) => WriteMode::Normal { offset },
Expand Down Expand Up @@ -1073,13 +1082,13 @@ impl TrampolineInterface {
) -> NTSTATUS {
let fs = &*(*file_system).UserContext.cast::<C>();
let file_name = U16CStr::from_ptr_str_mut(file_name);
let buffer = if buffer.is_null() {
None
} else {
let buffer = if !buffer.is_null() {
Some(std::slice::from_raw_parts_mut(
buffer.cast(),
psize.read() as usize,
))
} else {
None
};

match C::get_reparse_point_by_name(fs, file_name, is_directory != 0, buffer) {
Expand Down Expand Up @@ -1151,7 +1160,11 @@ impl TrampolineInterface {
let fs = &*(*file_system).UserContext.cast::<C>();
let fctx = C::FileContext::access(file_context);
let file_name = U16CStr::from_ptr_str(file_name);
let buffer = std::slice::from_raw_parts_mut(buffer.cast(), *p_size as usize);
let buffer = if !buffer.is_null() {
std::slice::from_raw_parts_mut(buffer.cast(), *p_size as usize)
} else {
&mut []
};

match C::get_reparse_point(fs, fctx, file_name, buffer) {
Ok(byte_transferred) => {
Expand Down Expand Up @@ -1180,7 +1193,11 @@ impl TrampolineInterface {
let fs = &*(*file_system).UserContext.cast::<C>();
let fctx = C::FileContext::access(file_context);
let file_name = U16CStr::from_ptr_str(file_name);
let buffer = std::slice::from_raw_parts_mut(buffer.cast(), size as usize);
let buffer = if !buffer.is_null() {
std::slice::from_raw_parts_mut(buffer.cast(), size as usize)
} else {
&mut []
};

match C::set_reparse_point(fs, fctx, file_name, buffer) {
Ok(()) => STATUS_SUCCESS,
Expand All @@ -1204,7 +1221,11 @@ impl TrampolineInterface {
let fs = &*(*file_system).UserContext.cast::<C>();
let fctx = C::FileContext::access(file_context);
let file_name = U16CStr::from_ptr_str(file_name);
let buffer = std::slice::from_raw_parts_mut(buffer.cast(), size as usize);
let buffer = if !buffer.is_null() {
std::slice::from_raw_parts_mut(buffer.cast(), size as usize)
} else {
&mut []
};

match C::delete_reparse_point(fs, fctx, file_name, buffer) {
Ok(()) => STATUS_SUCCESS,
Expand All @@ -1229,7 +1250,11 @@ impl TrampolineInterface {
) -> NTSTATUS {
let fs = &*(*file_system).UserContext.cast::<C>();
let fctx = C::FileContext::access(file_context);
let buffer = std::slice::from_raw_parts_mut(buffer.cast(), length as usize);
let buffer = if !buffer.is_null() {
std::slice::from_raw_parts_mut(buffer.cast(), length as usize)
} else {
&mut []
};

match C::get_stream_info(fs, fctx, buffer) {
Ok(bytes_transferred) => {
Expand Down Expand Up @@ -1299,9 +1324,16 @@ impl TrampolineInterface {
) -> NTSTATUS {
let fs = &*(*file_system).UserContext.cast::<C>();
let fctx = C::FileContext::access(file_context);
let input = std::slice::from_raw_parts(input_buffer.cast(), input_buffer_length as usize);
let output =
std::slice::from_raw_parts_mut(output_buffer.cast(), output_buffer_length as usize);
let input = if !input_buffer.is_null() {
std::slice::from_raw_parts(input_buffer.cast(), input_buffer_length as usize)
} else {
&[]
};
let output = if !output_buffer.is_null() {
std::slice::from_raw_parts_mut(output_buffer.cast(), output_buffer_length as usize)
} else {
&mut []
};

match C::control(fs, fctx, control_code, input, output) {
Ok(bytes_transferred) => {
Expand Down Expand Up @@ -1449,7 +1481,11 @@ impl TrampolineInterface {
let fs = &*(*file_system).UserContext.cast::<C>();
let file_name = U16CStr::from_ptr_str(file_name);
let sd = SecurityDescriptor::from_ptr(security_descriptor);
let buffer = std::slice::from_raw_parts(extra_buffer.cast(), extra_length as usize);
let buffer = if !extra_buffer.is_null() {
std::slice::from_raw_parts(extra_buffer.cast(), extra_length as usize)
} else {
&[]
};

match C::create_ex(
fs,
Expand Down Expand Up @@ -1535,7 +1571,11 @@ impl TrampolineInterface {
) -> NTSTATUS {
let fs = &*(*file_system).UserContext.cast::<C>();
let fctx = C::FileContext::access(file_context);
let buffer = std::slice::from_raw_parts(ea.cast(), ea_length as usize);
let buffer = if !ea.is_null() {
std::slice::from_raw_parts(ea.cast(), ea_length as usize)
} else {
&[]
};

match C::overwrite_ex(
fs,
Expand Down Expand Up @@ -1570,7 +1610,11 @@ impl TrampolineInterface {
) -> NTSTATUS {
let fs = &*(*file_system).UserContext.cast::<C>();
let fctx = C::FileContext::access(file_context);
let buffer = std::slice::from_raw_parts(ea.cast(), ea_length as usize);
let buffer = if !ea.is_null() {
std::slice::from_raw_parts(ea.cast(), ea_length as usize)
} else {
&[]
};

match C::get_ea(fs, fctx, buffer) {
Ok(bytes_transfered) => {
Expand Down Expand Up @@ -1599,7 +1643,11 @@ impl TrampolineInterface {
) -> NTSTATUS {
let fs = &*(*file_system).UserContext.cast::<C>();
let fctx = C::FileContext::access(file_context);
let buffer = std::slice::from_raw_parts(ea.cast(), ea_length as usize);
let buffer = if !ea.is_null() {
std::slice::from_raw_parts(ea.cast(), ea_length as usize)
} else {
&[]
};

match C::set_ea(fs, fctx, buffer) {
Ok(info) => {
Expand Down

0 comments on commit 4bc7cd7

Please sign in to comment.