about summary refs log tree commit diff
path: root/library/std/src/sys/pal/unix/fs.rs
AgeCommit message (Collapse)AuthorLines
2025-03-08Move fs into sysThalia Archibald-2315/+0
2025-03-06library: Use size_of from the prelude instead of importedThalia Archibald-2/+2
Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the prelude instead of importing or qualifying them. These functions were added to all preludes in Rust 1.80.
2025-02-17Rollup merge of #137165 - thaliaarchi:file-tell, r=ChrisDentonMatthias Krüger-0/+4
Use `tell` for `<File as Seek>::stream_position` Some platforms have a more efficient way to get the current offset of the file than by seeking. For example, Wasi has `fd_tell` and SOLID has `SOLID_FS_Ftell`. Implement `<File as Seek>::stream_position()` in terms of those. I do not use any APIs that were not already used in `std`. Although, the `libc` crate has [`ftell`](https://docs.rs/libc/latest/libc/fn.ftell.html), [`ftello`](https://docs.rs/libc/latest/libc/fn.ftello.html), and [`ftello64`](https://docs.rs/libc/latest/libc/fn.ftello64.html), I do not know platform coverage. It appears that Windows has no `tell`-like API. I have checked that it builds on each relevant platform.
2025-02-17Use tell for <File as Seek>::stream_positionThalia Archibald-0/+4
2025-02-10Fix &&str and trailing commas in io::const_error!Thalia Archibald-4/+3
2025-02-09Rollup merge of #136213 - erickt:fs, r=Mark-SimulacrumUrgau-1/+17
Allow Rust to use a number of libc filesystem calls This allows Rust on Fuchsia to use a number of function calls from libc: * dirfd * fdatasync * flock with LOCK_EX, LOCK_SH, LOCK_NB, LOCK_UN * fstatat cc #120426 try-job: dist-various-2
2025-02-03std::fs: further simplify dirent64 handlingRalf Jung-8/+6
2025-01-28Allow Rust to use a number of libc filesystem callsErick Tryzelaar-1/+17
This allows Rust on Fuchsia to use a number of function calls from libc: * dirfd * fdatasync * flock with LOCK_EX, LOCK_SH, LOCK_NB, LOCK_UN * fstatat
2025-01-14Update ReadDir::next in std::sys::pal::unix::fs to use `&raw const ↵Zachary S-23/+13
(*ptr).field` instead of `ptr.offset(...).cast()`. Also, the macro is only called three times, and all with the same local variable entry_ptr, so just use the local variable directly, and rename the macro to entry_field_ptr.
2025-01-01std::fs::DirEntry.metadata(): prefer use of lstat() on EmscriptenKleis Auke Wolthuizen-8/+1
Align it with musl, which also prefers using lstat() here.
2025-01-01Avoid use of LFS64 symbols on EmscriptenKleis Auke Wolthuizen-4/+1
Since Emscripten uses musl libc internally. Non-functional change: all LFS64 symbols were aliased to their non-LFS64 counterparts in rust-lang/libc@7c952dceaad4cdc35e00884fcb12a713d41a87e0.
2024-12-28Auto merge of #134547 - SUPERCILEX:unify-copy, r=thomccbors-23/+56
Unify fs::copy and io::copy on Linux Currently, `fs::copy` first tries a regular file copy (via copy_file_range) and then falls back to userspace read/write copying. We should use `io::copy` instead as it tries copy_file_range, sendfile, and splice before falling back to userspace copying. This was discovered here: https://github.com/SUPERCILEX/fuc/issues/40 Perf impact: `fs::copy` will now have two additional statx calls to decide which syscall to use. I wonder if we should get rid of the statx calls and only continue down the next fallback when the relevant syscalls say the FD isn't supported.
2024-12-24Fix compilation issues on other unixesAlex Saveau-2/+50
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2024-12-21Fix forgetting to save statx availability on successAlex Saveau-1/+5
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2024-12-21Eliminate redundant statx syscallsAlex Saveau-6/+9
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2024-12-21Unify fs::copy and io::copyAlex Saveau-19/+1
2024-11-26std: update internal uses of `io::const_error!`joboet-13/+13
2024-11-13Fix compilation error on Solaris due to flock usageChristopher Berner-0/+80
PR 130999 added the file_lock feature, but libc does not define flock() for the Solaris platform leading to a compilation error. Additionally, I went through all the Tier 2 platforms and read through their documentation to see whether flock was implemented. This turned up 5 more Unix platforms where flock is not supported, even though it may exist in the libc crate.
2024-11-11Rollup merge of #130999 - cberner:flock_pr, r=joboetMatthias Krüger-0/+37
Implement file_lock feature This adds lock(), lock_shared(), try_lock(), try_lock_shared(), and unlock() to File gated behind the file_lock feature flag This is the initial implementation of https://github.com/rust-lang/rust/issues/130994 for Unix and Windows platforms. I will follow it up with an implementation for WASI preview 2
2024-10-19replace STATX_ALL with (STATX_BASIC_STATS | STATX_BTIME) as former is deprecatedklensy-5/+5
2024-10-14Rollup merge of #128967 - devnexen:get_path_fbsd_upd, r=joboetMatthias Krüger-2/+2
std::fs::get_path freebsd update. what matters is we re doing the right things as doing sizeof, rather than passing KINFO_FILE_SIZE (only defined on intel architectures), the kernel making sure it matches the expectation in its side.
2024-10-13Implement file_lock featureChristopher Berner-0/+37
This adds lock(), lock_shared(), try_lock(), try_lock_shared(), and unlock() to File gated behind the file_lock feature flag
2024-10-13sys/unix: add comments for some Miri fallbacksRalf Jung-1/+1
2024-10-03std::fs::get_path freebsd update.David Carlier-2/+2
what matters is we re doing the right things as doing sizeof, rather than KINFO_FILE_SIZE (only defined on intel architectures), the kernel making sure it matches the expectation in its side.
2024-09-25Use `&raw` in the standard libraryJosh Stone-4/+4
Since the stabilization in #127679 has reached stage0, 1.82-beta, we can start using `&raw` freely, and even the soft-deprecated `ptr::addr_of!` and `ptr::addr_of_mut!` can stop allowing the unstable feature. I intentionally did not change any documentation or tests, but the rest of those macro uses are all now using `&raw const` or `&raw mut` in the standard library.
2024-09-24Initial std library support for NuttXHuang Qi-4/+15
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-6/+6
2024-09-11Limit `libc::link` usage to `nto70` target only, not NTO OSYuri Astrakhan-1/+1
It seems QNX 7.0 does not support `linkat` at all (most tests were failing). Limiting to QNX 7.0 only, while using `linkat` for the future versions seems like the right path forward (tested on 7.0). Fixes 129895
2024-09-03Port std library to RTEMSJan Sommer-2/+16
2024-08-30Squashed `aarch64_unknown_nto_qnx700` supportYuri Astrakhan-1/+1
2024-08-23Rollup merge of #127623 - lolbinarycat:fix_remove_dir_all, r=AmanieuMatthias Krüger-15/+34
fix: fs::remove_dir_all: treat internal ENOENT as success fixes #127576 try-job: test-various
2024-08-22fix: fs::remove_dir_all: treat ENOENT as successbinarycat-15/+34
fixes #127576 windows implementation still needs some work
2024-08-12trying common codepath for every unixesDavid Carlier-29/+0
2024-08-12std::fs: get_mode implementation for haiku.David Carlier-0/+2
2024-07-29Reformat `use` declarations.Nicholas Nethercote-28/+23
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-24Rollup merge of #127480 - biabbas:vxworks, r=workingjubileeMatthias Krüger-2/+22
Fix build failure on vxworks #127084 PR to address issue #127084 . 1. Skip `reset_segpipe` for vxworks 2. Return unimplemented error for vxworks from settimes and lchown 3. Temporarily skip dirfd for vxworks 4. Add allow unused unsafe on read_at and write_at functions in unix/fs.rs 5. Using cfg disable ON_BROKEN_PIPE_FLAG_USED and on_broken_pipe_flag_used() for vxworks 6. Remove old crate::syscommon::thread::min_stack() reference from process_vxworks.rs and update to set stack size of rtpthread Thank you.
2024-07-24Add chroot unsupported implementation for VxWorksB I Mohammed Abbas-1/+7
2024-07-23Fix return type of FileAttr methods on AIX targetTaylor Foxhall-3/+3
At some point it seems `SystemTime::new` changed from returning `SystemTime` to `io::Result<SystemTime>`. This seems to have been addressed on other platforms, but was never changed for AIX. This was caught by running ``` python3 x.py build --host x86_64-unknown-linux-gnu --target powerpc64-ibm-aix ```
2024-07-23Disable dirfd for vxworks, Return unsupported error from set_times and ↵B I Mohammed Abbas-2/+16
lchown for vxworks
2024-07-13std::unix::fs: removing, now useless, layers predating macOs 10.10.David Carlier-59/+1
fdopendir, openat and unlinkat are available since yosemite but we support sierra as minimum.
2024-07-03Fall back on remove dir implementation for vxworksB I Mohammed Abbas-1/+3
2024-06-24Rollup merge of #126807 - devnexen:copy_file_macos_simpl, r=Mark-SimulacrumMatthias Krüger-35/+15
std::unix::fs: copy simplification for apple. since we do support from macOs Sierra, we avoid the little runtime overhead with the fclonefileat symbol check.
2024-06-22Rollup merge of #126140 - eduardosm:stabilize-fs_try_exists, r=AmanieuMatthias Krüger-1/+1
Rename `std::fs::try_exists` to `std::fs::exists` and stabilize fs_try_exists FCP completed in tracking issue. Tracking issue: https://github.com/rust-lang/rust/issues/83186 Closes https://github.com/rust-lang/rust/issues/83186 Stabilized API: ```rust mod fs { pub fn exists<P: AsRef<Path>>(path: P) -> io::Result<bool>; } ```
2024-06-21std::unix::fs: copy simplification for apple.David Carlier-35/+15
since we do support from macOs Sierra, we avoid the little runtime overhead with the fclonefileat symbol check.
2024-06-13std::unix::fs::link using direct linkat call for Solaris and macOs.David Carlier-19/+2
Since we support solaris 11 and macOs Sierra as minimum, we can get rid of the runtime overhead.
2024-06-11Rename `std::fs::try_exists` to `std::fs::exists` and stabilize fs_try_existsEduardo Sánchez Muñoz-1/+1
2024-06-08Rollup merge of #125998 - devnexen:get_mode_illumos, r=NilstriebLeón Orell Valerian Liehr-0/+4
std::unix::fs::get_mode implementation for illumos/solaris. they both support the F_GETFL fctnl flag/O_ACCMODE mask to get the file descriptor access modes.
2024-06-05Rollup merge of #125940 - devnexen:unix_fs_netbsd_get_path, r=cuviperMatthias Krüger-9/+13
std::unix::fs::get_path: using fcntl codepath for netbsd instead. on netbsd, procfs is not as central as on linux/solaris thus can be perfectly not mounted. Thus using fcntl with F_GETPATH, the kernel deals with MAXPATHLEN internally too.
2024-06-04std::unix::fs::get_mode implementation for illumos/solaris.David Carlier-0/+4
they both support the F_GETFL fctnl flag/O_ACCMODE mask to get the file descriptor access modes.
2024-06-04std::unix::fs::get_path: using fcntl codepath for netbsd instead.David Carlier-9/+13
on netbsd, procfs is not as central as on linux/solaris thus can be perfectly not mounted. Thus using fcntl with F_GETPATH, the kernel deals with MAXPATHLEN internally too.