Skip to content

Commit

Permalink
fix(cpio): correct dev_t -> rmajor/rminor mapping
Browse files Browse the repository at this point in the history
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: #1695
Reported-by: Ethan Wu <ethanwu10@gmail.com>
Signed-off-by: David Disseldorp <ddiss@suse.de>
  • Loading branch information
ddiss authored and johannbg committed Feb 17, 2022
1 parent 8bd7ddf commit acc629a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/dracut-cpio/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,12 @@ fn archive_path<W: Seek + Write>(
// no zero terminator for symlink target path
}

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

if ftype.is_file() {
Expand Down

0 comments on commit acc629a

Please sign in to comment.