MCPcopy Create free account
hub / github.com/IBM/ACE-RISCV / attach_tap

Function attach_tap

tools/cove_tap_tool/src/attach.rs:12–37  ·  view source on GitHub ↗
(
    kernel_file: String,
    tap_file_name: String,
    output_file: Option<String>,
)

Source from the content-addressed store, hash-verified

10use std::io::SeekFrom;
11
12pub fn attach_tap(
13 kernel_file: String,
14 tap_file_name: String,
15 output_file: Option<String>,
16) -> Result<(), Error> {
17 let output_file_name = match output_file {
18 Some(f) if kernel_file != f => {
19 std::fs::copy(kernel_file, f.clone())?;
20 f
21 }
22 Some(f) => f,
23 None => kernel_file,
24 };
25 let offset = find_placehoder(&output_file_name)?;
26 // clear the placeholder
27 let mut output_file = OpenOptions::new().write(true).open(output_file_name)?;
28 output_file.seek(SeekFrom::Start(offset))?;
29 (riscv_cove_tap::ACE_HEADER_SIZE..riscv_cove_tap::ACE_MAX_TAP_SIZE)
30 .try_for_each(|_| output_file.write_u8(0u8))?;
31 // write expected TAP from the beginning of the offset
32 output_file.seek(SeekFrom::Start(offset))?;
33 let mut tap_file = OpenOptions::new().read(true).open(tap_file_name)?;
34 std::io::copy(&mut tap_file, &mut output_file)?;
35 println!("TAP attached successfully");
36 Ok(())
37}
38
39fn find_placehoder(output_file_name: &str) -> Result<u64, Error> {
40 let output_file = OpenOptions::new().read(true).open(output_file_name)?;

Callers 1

mainFunction · 0.85

Calls 3

find_placehoderFunction · 0.85
writeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected