(
image_path: &Path,
guest_path: &str,
contents: &[u8],
)
| 154 | } |
| 155 | |
| 156 | pub 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 | |
| 185 | pub fn set_rootfs_image_file_mode( |
| 186 | image_path: &Path, |
no test coverage detected