Переглянути джерело

fix(file): restore unsafe blocks for libc major/minor device id

e3c5fa745b29b14e9b2b5c96167e20fda3ec845c removed the unsafe blocks for
libc::major and libc::minor after the libc crate inlined the macros they
are defined as on most platforms. On illumos and Solaris, the libc crate
still calls the C binding, so this change broke compilation there. Add
back the unsafe blocks, and allow the unused_unsafe lint for the vast
majority of platforms where it would apply.

Signed-off-by: iliana etaoin <iliana@oxide.computer>
iliana etaoin 7 місяців тому
батько
коміт
640ee13634
1 змінених файлів з 14 додано та 13 видалено
  1. 14 13
      src/fs/file.rs

+ 14 - 13
src/fs/file.rs

@@ -606,20 +606,21 @@ impl<'dir> File<'dir> {
             // 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)]
+            //
+            // On illumos and Solaris, major and minor are extern "C" fns and
+            // therefore unsafe; on other platforms the functions are defined as
+            // macros and copied as const fns in the libc crate.
+            #[allow(trivial_numeric_casts, unused_unsafe)]
             #[allow(clippy::unnecessary_cast, clippy::useless_conversion)]
-            f::Size::DeviceIDs(f::DeviceIDs {
-                major: libc::major(
-                    device_id
-                        .try_into()
-                        .expect("Malformed device major ID when getting filesize"),
-                ) as u32,
-                minor: libc::minor(
-                    device_id
-                        .try_into()
-                        .expect("Malformed device major ID when getting filesize"),
-                ) as u32,
-            })
+            {
+                let device_id = device_id
+                    .try_into()
+                    .expect("Malformed device major ID when getting filesize");
+                f::Size::DeviceIDs(f::DeviceIDs {
+                    major: unsafe { libc::major(device_id) as u32 },
+                    minor: unsafe { libc::minor(device_id) as u32 },
+                })
+            }
         } else if self.is_file() {
             f::Size::Some(self.metadata().map_or(0, std::fs::Metadata::len))
         } else {