Просмотр исходного кода

fix(fs): Linux uses u32 for major/minor device numbers

Robert Minsk 2 лет назад
Родитель
Сommit
24a89a57a5
2 измененных файлов с 11 добавлено и 4 удалено
  1. 2 2
      src/fs/fields.rs
  2. 9 2
      src/fs/file.rs

+ 2 - 2
src/fs/fields.rs

@@ -190,8 +190,8 @@ pub enum Size {
 /// - <http://www.lanana.org/docs/device-list/devices-2.6+.txt>
 #[derive(Copy, Clone)]
 pub struct DeviceIDs {
-    pub major: i32,
-    pub minor: i32,
+    pub major: u32,
+    pub minor: u32,
 }
 
 

+ 9 - 2
src/fs/file.rs

@@ -458,10 +458,17 @@ impl<'dir> File<'dir> {
         else if self.is_char_device() || self.is_block_device() {
             let device_id = self.metadata.rdev();
 
+            // MacOS and Linux have different arguments and return types for the
+            // functions major and minor.  On Linux the try_into().unwrap() and
+            // the "as u32" cast are not needed.  We turn off the warning to
+            // allow it to compile cleanly on Linux.
+            #[allow(trivial_numeric_casts)]
+            #[allow(clippy::unnecessary_cast)]
+            #[allow(clippy::useless_conversion)]
             f::Size::DeviceIDs(f::DeviceIDs {
                 // SAFETY: Calling libc function to decompose the device_id
-                major: unsafe { libc::major(device_id.try_into().unwrap()) },
-                minor: unsafe { libc::minor(device_id.try_into().unwrap()) },
+                major: unsafe { libc::major(device_id.try_into().unwrap()) } as u32,
+                minor: unsafe { libc::minor(device_id.try_into().unwrap()) } as u32,
             })
         }
         else if self.is_link() && self.deref_links {