From b05277e44d7e1fda38a2ae5f8090ff3bad83ad30 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Mon, 16 Nov 2026 00:13:39 +0000 Subject: [PATCH 1/3] fix(fs): resolve compile error for vita --- src/backend/libc/fs/dir.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/backend/libc/fs/dir.rs b/src/backend/libc/fs/dir.rs index 19a909078..77a7c1de7 100644 --- a/src/backend/libc/fs/dir.rs +++ b/src/backend/libc/fs/dir.rs @@ -87,6 +87,7 @@ impl Dir { /// - [POSIX] /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/dirfd.html + #[cfg(not(target_os = "vita"))] #[inline] #[doc(alias = "dirfd")] pub fn fd<'a>(&'a self) -> io::Result> { From 03a8dfd0ebcc85425f5806b57d25c112634ab2cc Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Sun, 15 Nov 2026 20:29:17 +0000 Subject: [PATCH 2/3] feat(fs): implement `mknod` --- src/backend/libc/fs/syscalls.rs | 16 +++++++++------- src/backend/linux_raw/fs/syscalls.rs | 5 +++++ src/fs/abs.rs | 16 ++++++++++++++++ tests/fs/main.rs | 1 + tests/fs/mknodat.rs | 13 +++++++++++++ 5 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/backend/libc/fs/syscalls.rs b/src/backend/libc/fs/syscalls.rs index 5b8962f98..26ce3ee36 100644 --- a/src/backend/libc/fs/syscalls.rs +++ b/src/backend/libc/fs/syscalls.rs @@ -51,12 +51,7 @@ use crate::fs::SealFlags; use crate::fs::StatFs; #[cfg(not(any(target_os = "espidf", target_os = "horizon", target_os = "vita")))] use crate::fs::Timestamps; -#[cfg(not(any( - target_os = "espidf", - target_os = "horizon", - target_os = "vita", - target_os = "wasi" -)))] +#[cfg(not(target_os = "wasi"))] use crate::fs::{Dev, FileType}; use crate::fs::{Mode, OFlags, SeekFrom, Stat}; #[cfg(not(target_os = "wasi"))] @@ -1187,6 +1182,13 @@ pub(crate) fn chownat( )) } } +#[cfg(not(target_os = "wasi"))] +pub(crate) fn mknod(path: &CStr, file_type: FileType, mode: Mode, dev: Dev) -> io::Result<()> { + let pathname = c_str(path); + let mode = (mode.bits() | file_type.as_raw_mode()) as c::mode_t; + let dev = dev.try_into().map_err(|_| io::Errno::PERM)?; + unsafe { ret(c::mknod(pathname, mode, dev)) } +} #[cfg(not(any( target_os = "espidf", @@ -1204,7 +1206,7 @@ pub(crate) fn mknodat( let dirfd = borrowed_fd(dirfd); let pathname = c_str(path); let mode = (mode.bits() | file_type.as_raw_mode()) as c::mode_t; - let dev = dev.try_into().map_err(|_e| io::Errno::PERM)?; + let dev = dev.try_into().map_err(|_| io::Errno::PERM)?; // Apple platforms before macOS 13.0, iOS 16.0, tvOS 16.0, and watchOS 9.0 // lack `mknodat`. diff --git a/src/backend/linux_raw/fs/syscalls.rs b/src/backend/linux_raw/fs/syscalls.rs index 149ee078a..6a76c0b2d 100644 --- a/src/backend/linux_raw/fs/syscalls.rs +++ b/src/backend/linux_raw/fs/syscalls.rs @@ -247,6 +247,11 @@ pub(crate) fn mknodat( } } +#[inline] +pub(crate) fn mknod(path: &CStr, file_type: FileType, mode: Mode, dev: u64) -> io::Result<()> { + mknodat(crate::fs::CWD, path, file_type, mode, dev) +} + #[inline] pub(crate) fn seek(fd: BorrowedFd<'_>, pos: SeekFrom) -> io::Result { let (whence, offset) = match pos { diff --git a/src/fs/abs.rs b/src/fs/abs.rs index 6642fee65..d12fff956 100644 --- a/src/fs/abs.rs +++ b/src/fs/abs.rs @@ -17,6 +17,8 @@ use crate::fs::Access; use crate::fs::StatFs; #[cfg(not(any(target_os = "wasi")))] use crate::fs::StatVfs; +#[cfg(not(target_os = "wasi"))] +use crate::fs::{Dev, FileType}; use crate::fs::{Mode, OFlags, Stat}; #[cfg(not(target_os = "wasi"))] use crate::ugid::{Gid, Uid}; @@ -231,6 +233,20 @@ pub fn mkdir(path: P, mode: Mode) -> io::Result<()> { path.into_with_c_str(|path| backend::fs::syscalls::mkdir(path, mode)) } +/// `mknod(path, mode, dev)`—Creates a special or normal file. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/mknod.html +/// [Linux]: https://man7.org/linux/man-pages/man2/mknod.2.html +#[cfg(not(target_os = "wasi"))] +#[inline] +pub fn mknod(path: P, file_type: FileType, mode: Mode, dev: Dev) -> io::Result<()> { + path.into_with_c_str(|path| backend::fs::syscalls::mknod(path, file_type, mode, dev)) +} + /// `access(path, access)`—Tests permissions for a file or directory. /// /// # References diff --git a/tests/fs/main.rs b/tests/fs/main.rs index a0bfc3343..1c30cb6d0 100644 --- a/tests/fs/main.rs +++ b/tests/fs/main.rs @@ -40,6 +40,7 @@ mod long_paths; #[cfg(not(any(target_os = "haiku", target_os = "wasi")))] mod makedev; mod mkdirat; +#[cfg(not(target_os = "wasi"))] mod mknodat; mod negative_timestamp; #[cfg(linux_kernel)] diff --git a/tests/fs/mknodat.rs b/tests/fs/mknodat.rs index 8ba53cee0..c42be2a53 100644 --- a/tests/fs/mknodat.rs +++ b/tests/fs/mknodat.rs @@ -1,3 +1,16 @@ +#[test] +fn test_mknod() { + use rustix::fs::{mknod, stat, unlink, FileType, Mode}; + + let tmp = tempfile::tempdir().unwrap(); + let path = tmp.path().join("file"); + + mknod(&path, FileType::Fifo, Mode::empty(), 0).unwrap(); + let stat = stat(&path).unwrap(); + assert_eq!(FileType::from_raw_mode(stat.st_mode), FileType::Fifo); + unlink(&path).unwrap(); +} + #[cfg(not(any(apple, target_os = "wasi")))] #[test] fn test_mknodat() { From f6c96c073362c2c96df448ac12cdf034c30f054a Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Mon, 16 Nov 2026 00:43:29 +0000 Subject: [PATCH 3/3] feat(fs): implement `mkfifo` --- src/fs/abs.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/fs/abs.rs b/src/fs/abs.rs index d12fff956..a2d1384fd 100644 --- a/src/fs/abs.rs +++ b/src/fs/abs.rs @@ -233,6 +233,20 @@ pub fn mkdir(path: P, mode: Mode) -> io::Result<()> { path.into_with_c_str(|path| backend::fs::syscalls::mkdir(path, mode)) } +/// `mkfifo(path, mode)`—Creates a FIFO special file. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/mkfifo.html +/// [Linux]: https://man7.org/linux/man-pages/man3/mkfifo.3.html +#[cfg(not(target_os = "wasi"))] +#[inline] +pub fn mkfifo(path: P, mode: Mode) -> io::Result<()> { + mknod(path, FileType::Fifo, mode, 0) +} + /// `mknod(path, mode, dev)`—Creates a special or normal file. /// /// # References