Skip to content

Commit 0af11c5

Browse files
ddissConan-Kudo
authored andcommitted
fix(cpio): write zeros instead of seek for padding and alignment
This is a workaround for GRUB2's Btrfs implementation, which doesn't correctly handle gaps between extents. A fix has already been proposed upstream via https://lists.gnu.org/archive/html/grub-devel/2021-10/msg00206.html Given that this bug is severe, it makes sense to include this minimal workaround. Signed-off-by: David Disseldorp <[email protected]>
1 parent 3326e4c commit 0af11c5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Diff for: src/dracut-cpio/src/main.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,10 @@ impl ArchiveState {
255255
self.off += fname.len() as u64;
256256
// +1 as padding starts after fname nulterm
257257
let seeklen = 1 + archive_padlen(self.off + 1, 4);
258-
writer.seek(io::SeekFrom::Current(seeklen as i64))?;
258+
{
259+
let z = vec![0u8; seeklen.try_into().unwrap()];
260+
writer.write_all(&z)?;
261+
}
259262
self.off += seeklen;
260263
}
261264
*mapped_ino = Some((*hl).mapped_ino);
@@ -469,7 +472,10 @@ fn archive_path<W: Seek + Write>(
469472
let padding_len = archive_padlen(state.off + seek_len as u64, 4);
470473
seek_len += padding_len as i64;
471474
}
472-
writer.seek(io::SeekFrom::Current(seek_len))?;
475+
{
476+
let z = vec![0u8; seek_len.try_into().unwrap()];
477+
writer.write_all(&z)?;
478+
}
473479
state.off += seek_len as u64;
474480

475481
// io::copy() can reflink: https://github.com/rust-lang/rust/pull/75272 \o/

0 commit comments

Comments
 (0)