From 311c9baf659b4ca084f407a6335e7439e45859db Mon Sep 17 00:00:00 2001 From: Benjamin Sago Date: Sun, 11 Apr 2021 23:34:29 +0100 Subject: [PATCH] Explain device IDs with a comment --- src/fs/file.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/fs/file.rs b/src/fs/file.rs index 0df998c..b57777d 100644 --- a/src/fs/file.rs +++ b/src/fs/file.rs @@ -319,10 +319,15 @@ impl<'dir> File<'dir> { f::Size::None } else if self.is_char_device() || self.is_block_device() { - let dev = self.metadata.rdev(); + let device_ids = self.metadata.rdev().to_be_bytes(); + + // In C-land, getting the major and minor device IDs is done with + // preprocessor macros called `major` and `minor` that depend on + // the size of `dev_t`, but we just take the second-to-last and + // last bytes. f::Size::DeviceIDs(f::DeviceIDs { - major: (dev / 256) as u8, - minor: (dev % 256) as u8, + major: device_ids[6], + minor: device_ids[7], }) } else {