Skip to content

Commit acc629a

Browse files
ddissjohannbg
authored andcommitted
fix(cpio): correct dev_t -> rmajor/rminor mapping
dev_t -> major/minor number mapping is more complicated than the incorrect major=(dev_t >> 8) minor=(dev_t & 0xff) mapping that we currently perform. Fix mapping to match Linux / glibc behaviour. Fixes: dracutdevs#1695 Reported-by: Ethan Wu <ethanwu10@gmail.com> Signed-off-by: David Disseldorp <ddiss@suse.de>
1 parent 8bd7ddf commit acc629a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/dracut-cpio/src/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,12 @@ fn archive_path<W: Seek + Write>(
361361
// no zero terminator for symlink target path
362362
}
363363

364+
// Linux kernel uses 32-bit dev_t, encoded as mmmM MMmm. glibc uses 64-bit
365+
// MMMM Mmmm mmmM MMmm, which is compatible with the former.
364366
if ftype.is_block_device() || ftype.is_char_device() {
365-
rmajor = (md.rdev() >> 8) as u32;
366-
rminor = (md.rdev() & 0xff) as u32;
367+
let rd = md.rdev();
368+
rmajor = (((rd >> 32) & 0xfffff000) | ((rd >> 8) & 0x00000fff)) as u32;
369+
rminor = (((rd >> 12) & 0xffffff00) | (rd & 0x000000ff)) as u32;
367370
}
368371

369372
if ftype.is_file() {

0 commit comments

Comments
 (0)