MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / write_rootfs_image_file

Function write_rootfs_image_file

crates/openshell-driver-vm/src/rootfs.rs:156–183  ·  view source on GitHub ↗
(
    image_path: &Path,
    guest_path: &str,
    contents: &[u8],
)

Source from the content-addressed store, hash-verified

154}
155
156pub fn write_rootfs_image_file(
157 image_path: &Path,
158 guest_path: &str,
159 contents: &[u8],
160) -> Result<(), String> {
161 ensure_rootfs_image_parent_dirs(image_path, guest_path);
162
163 let tmp_path = temporary_injection_path(image_path);
164 fs::write(&tmp_path, contents).map_err(|e| format!("write {}: {e}", tmp_path.display()))?;
165 let Some(quoted_guest_path) = debugfs_quote_absolute_path(guest_path) else {
166 let _ = fs::remove_file(&tmp_path);
167 return Err(format!("invalid debugfs guest path '{guest_path}'"));
168 };
169 let Some(quoted_tmp_path) = debugfs_quote_argument(&tmp_path.to_string_lossy()) else {
170 let _ = fs::remove_file(&tmp_path);
171 return Err(format!(
172 "invalid debugfs injection path '{}'",
173 tmp_path.display()
174 ));
175 };
176 let _ = run_debugfs(image_path, &format!("rm {quoted_guest_path}"));
177 let result = run_debugfs(
178 image_path,
179 &format!("write {quoted_tmp_path} {quoted_guest_path}"),
180 );
181 let _ = fs::remove_file(&tmp_path);
182 result
183}
184
185pub fn set_rootfs_image_file_mode(
186 image_path: &Path,

Calls 5

temporary_injection_pathFunction · 0.85
debugfs_quote_argumentFunction · 0.85
run_debugfsFunction · 0.85

Tested by

no test coverage detected