From 7c88484d6419b41f44c93368224de7d5d3b6a8f9 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 16 Apr 2024 19:45:01 -0700 Subject: [PATCH] Fix #7988 --- native/src/base/files.rs | 10 +++++----- native/src/boot/cpio.rs | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/native/src/base/files.rs b/native/src/base/files.rs index 751d223c2..2ff7f7520 100644 --- a/native/src/base/files.rs +++ b/native/src/base/files.rs @@ -155,7 +155,7 @@ impl FileAttr { #[inline(always)] #[allow(clippy::unnecessary_cast)] fn is(&self, mode: mode_t) -> bool { - (self.st.st_mode & libc::S_IFMT as u32) as mode_t == mode + (self.st.st_mode & libc::S_IFMT as c_uint) as mode_t == mode } pub fn is_dir(&self) -> bool { @@ -895,18 +895,18 @@ pub(crate) fn map_file(path: &Utf8CStr, rw: bool) -> io::Result<&'static mut [u8 const BLKGETSIZE64: u32 = 0x80041272; let flag = if rw { O_RDWR } else { O_RDONLY }; - let f = File::from(open_fd!(path, flag | O_CLOEXEC)?); + let file = FsPath::from(path).open(flag | O_CLOEXEC)?; - let attr = FsPath::from(path).get_attr()?; + let attr = fd_get_attr(file.as_raw_fd())?; let sz = if attr.is_block_device() { let mut sz = 0_u64; - unsafe { ioctl(f.as_raw_fd(), BLKGETSIZE64, &mut sz) }.as_os_err()?; + unsafe { ioctl(file.as_raw_fd(), BLKGETSIZE64, &mut sz) }.as_os_err()?; sz } else { attr.st.st_size as u64 }; - map_fd(f.as_fd(), sz as usize, rw) + map_fd(file.as_fd(), sz as usize, rw) } pub(crate) fn map_fd(fd: BorrowedFd, sz: usize, rw: bool) -> io::Result<&'static mut [u8]> { diff --git a/native/src/boot/cpio.rs b/native/src/boot/cpio.rs index e5a52919d..22fa5caa8 100644 --- a/native/src/boot/cpio.rs +++ b/native/src/boot/cpio.rs @@ -407,7 +407,8 @@ impl Cpio { let rdevmajor: dev_t; let rdevminor: dev_t; - let mode = if attr.is_file() { + // Treat symlinks as regular files as symlinks are created by the 'ln TARGET ENTRY' command + let mode = if attr.is_file() || attr.is_symlink() { rdevmajor = 0; rdevminor = 0; file.open(O_RDONLY | O_CLOEXEC)?.read_to_end(&mut content)?;