about summary refs log tree commit diff
path: root/library/std/src/sys/fs
AgeCommit message (Collapse)AuthorLines
2025-09-08Rust build fails on OpenBSD after using file_lock featureSebastien Marie-0/+10
PR 130999 added the file_lock feature, but doesn't included OpenBSD in the supported targets (Tier 3 platform), leading to a compilation error ("try_lock() not supported"). (cherry picked from commit 8792010768cff60d202b3608e6918be3199aeae2)
2025-07-09Fix VxWorks build errorsB I Mohammed Abbas-1/+0
2025-06-28Workaround for mem safety in third party dllsChris Denton-9/+10
2025-06-13Windows: make read_dir stop iterating on errorChris Denton-0/+1
2025-06-05Optimize `Seek::stream_len` impl for `File`Tobias Bucher-0/+37
It uses the file metadata on Unix with a fallback for files incorrectly reported as zero-sized. It uses `GetFileSizeEx` on Windows. This reduces the number of syscalls needed for determining the file size of an open file from 3 to 1.
2025-05-27Rollup merge of #141312 - cberner:filelock_from, r=joshtriplettMatthias Krüger-8/+2
Add From<TryLockError> for io::Error Adds a `From` impl to make error propagation easier, as discussed in the tracking issue `TryLockError` is unstable under the "file_lock" feature. The related tracking issue is https://github.com/rust-lang/rust/issues/130994 This PR also cleanups the Windows implementation of `try_lock()` and `try_lock_shared()` as [discussed here](https://github.com/rust-lang/rust/pull/140718#discussion_r2076678485)
2025-05-20Remove unnecessary handling of ERROR_IO_PENDINGChristopher Berner-8/+2
try_lock() and try_lock_shared() do not need to handle these per the discussion in https://github.com/rust-lang/rust/pull/140718#discussion_r2076678485
2025-05-14Fix settimes for vxworksB I Mohammed Abbas-2/+1
2025-05-03Rollup merge of #139343 - cberner:filelock_wouldblock, r=workingjubileeMatthias Krüger-41/+58
Change signature of File::try_lock and File::try_lock_shared These methods now return Result<(), TryLockError> instead of Result<bool, Error> to make their use less errorprone These methods are unstable under the "file_lock" feature. The related tracking issue is https://github.com/rust-lang/rust/pull/130999 and this PR changes the signatures as discussed by libs-api: https://github.com/rust-lang/rust/issues/130994#issuecomment-2770838848
2025-05-01Change signature of File::try_lock and File::try_lock_sharedChristopher Berner-41/+58
These methods now return Result<(), TryLockError> instead of Result<bool, Error> to make their use less errorprone
2025-04-27use generic Atomic type where possibleChristopher Durham-4/+4
in core/alloc/std only for now, and ignoring test files Co-authored-by: Pavel Grigorenko <GrigorenkoPV@ya.ru>
2025-04-24Rollup merge of #139450 - NobodyXu:new-api/make-fifo, r=tgross35Matthias Krüger-1/+7
Impl new API `std::os::unix::fs::mkfifo` under feature `unix_fifo` Tracking issue #139324
2025-04-23Impl new API `std::os::unix::fs::mkfifo` under feature `unix_fifo`Jiahao XU-1/+7
Tracking issue #139324 Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2025-04-18std: Use fstatat() on illumosPatrick Mooney-3/+6
2025-04-17Rollup merge of #139667 - 1c3t3a:remove-no-sanitize, r=m-ou-seMatthias Krüger-14/+0
cfi: Remove #[no_sanitize(cfi)] for extern weak functions Previously (https://github.com/rust-lang/rust/pull/115200, https://github.com/rust-lang/rust/pull/138002), we added `#[no_sanitize(cfi)]` to all code paths that call to a weakly linked function. In https://github.com/rust-lang/rust/pull/138349 we fixed the root cause for this issue, which means we can now remove the corresponding attributes. r? `@rcvalle`
2025-04-13Rollup merge of #139683 - ChrisDenton:windows-with-native, r=tgross35,joboetChris Denton-47/+52
Use `with_native_path` for Windows Ideally, each platform should use their own native path type internally. This will, for example, allow passing a UTF-16 string directly to `std::fs::File::open` and therefore avoid the need for allocating a new null-terminated wide string. However, doing that for every function and platform all at once makes for a large PR that is way too prone to breaking. So this just does some of the Windows parts. As with the previous Unix PR (#138832) this is intended to be merely a refactoring so I've avoided anything that may require more substantial changes.
2025-04-12Rollup merge of #139382 - ChrisDenton:windows-bindgen-0-61, r=Mark-SimulacrumChris Denton-1/+1
Update windows-bindgen to 0.61.0 This updates the automatically generate Windows API bindings. Not much changed this time: - There's now `Default` implementations for many types, which is convenient. It does however conflict with one place where we implemented a non-zeroed default (to set the length field). But that's no big problem. - The `--no-core` flag has been renamed to `--no-deps` to more accurately reflect its meaning (i.e. generate all necessary code without requiring additional dependencies). - The `--link` flag allows us to set the location of the `link!` macro. Currently we use our workspace's `windows_targets` crate but we could move it into library/std using `--link`. However, this would need to be co-ordinated with the `backtrace` crate (which is a separate crate but included in std using `#[path]`). So I've left that for another time.
2025-04-11Use with_native_path for WindowsChris Denton-47/+52
Also add a WCStr type
2025-04-11cfi: Remove #[no_sanitize(cfi)] for extern weak functionsBastian Kersting-14/+0
Previously (https://github.com/rust-lang/rust/pull/115200, https://github.com/rust-lang/rust/pull/138002), we added `#[no_sanitize(cfi)]` to all code paths that call to a weakly linked function. In https://github.com/rust-lang/rust/pull/138349 we fixed the root cause for this issue, which means we can now remove the corresponding attributes.
2025-04-05Rollup merge of #139092 - thaliaarchi:move-fd-pal, r=joboetMatthias Krüger-1/+1
Move `fd` into `std::sys` Move platform definitions of `fd` into `std::sys`, as part of https://github.com/rust-lang/rust/issues/117276. Unlike other modules directly under `std::sys`, this is only available on some platforms and I have not provided a fallback abstraction for unsupported platforms. That is similar to how `std::os::fd` is gated to only supported platforms. Also, fix the `unsafe_op_in_unsafe_fn` lint, which was allowed for the Unix fd impl. Since macro expansions from `std::sys::pal::unix::weak` trigger this lint, fix it there too. cc `@joboet,` `@ChrisDenton` try-job: x86_64-gnu-aux
2025-04-04Move fd into sysThalia Archibald-1/+1
2025-04-04Update windows-bindgen to 0.61.0Chris Denton-1/+1
2025-04-01Auto merge of #138928 - ChrisDenton:fix-uwp, r=tgross35bors-1/+1
Fix UWP reparse point check Fixes #138921
2025-03-29Rollup merge of #138832 - ChrisDenton:with_native_path, r=joboetMatthias Krüger-107/+173
Start using `with_native_path` in `std::sys::fs` Ideally, each platform should use their own native path type internally. This will, for example, allow passing a `CStr` directly to `std::fs::File::open` and therefore avoid the need for allocating a new null-terminated C string. However, doing that for every function and platform all at once makes for a large PR that is way too prone to breaking. So this PR does some minimal refactoring which should help progress towards that goal. The changes are Unix-only and even then I avoided functions that require more changes so that this PR is just moving things around. r? joboet
2025-03-29Start using with_native_path in std::sys::fsChris Denton-107/+173
2025-03-26Change the syntax of the internal `weak!` macroMads Marquart-6/+10
Change the syntax to include parameter names and a trailing semicolon. Motivation: - Mirror the `syscall!` macro. - Allow rustfmt to format it (when wrapped in parentheses). - For better documentation (having the parameter names available in the source code is a bit nicer). - Allow future improvements to this macro where we can sometimes use the symbol directly when it's statically known to be available.
2025-03-25Fix UWP reparse point checkChris Denton-1/+1
2025-03-24Rollup merge of #138662 - Ayush1325:uefi-fs-1, r=nicholasbishop,petrochenkovMatthias Krüger-12/+62
Implement some basics in UEFI fs - Just getting some basics out of the way while waiting for #138236 to be merged. - Adds `fs::canonicalize`. Should be same as absolute in case of UEFI since there is no symlink support and absolute path is guaranteed to be uniqe according to spec. - Make `fs::lstat` same as `fs::stat`. Should be same since UEFI does not have symlink support. - Implement `OptionOptions`. cc ````@nicholasbishop```` ````@dvdhrm````
2025-03-24std: fs: uefi: Implement OpenOptionsAyush Singh-8/+58
UEFI does not have specific modes for create_new, truncate and append. So those need to to be simulated after opening the file. Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-03-24std: fs: uefi: Make lstat call statAyush Singh-2/+2
- UEFI does not have symlinks. So lstat and stat should behave the same. Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-03-24std: fs: uefi: Implement canonicalizeAyush Singh-2/+2
- Should be same as absolute in UEFI since there are no symlinks. - Also each absolute path representation should be unique according to the UEFI specification. Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-03-23Rollup merge of #138671 - ChrisDenton:filetype, r=joshtriplettJacob Pratt-18/+15
Fix `FileType` `PartialEq` implementation on Windows Fixes #138668 On Windows the [`FileType`](https://doc.rust-lang.org/stable/std/fs/struct.FileType.html) struct was deriving `PartialEq` which in turn means it was doing a bit-for-bit comparison on the file attributes and reparse point. This is wrong because `attributes` may contain many things unrelated to file type. `FileType` on Windows allows for four possible combinations (see also [`FileTypeExt`](https://doc.rust-lang.org/stable/std/os/windows/fs/trait.FileTypeExt.html)): `file`, `dir`, `symlink_file` and `symlink_dir`. So the new implementation makes sure both symlink and directory information match (and only those things). This could be considered just a bug fix but it is a behaviour change so someone from libs-api might want to FCP this (or might not)...
2025-03-23Rollup merge of #138667 - Ayush1325:uefi-mkdir, r=joboetMichael Goulet-4/+30
std: uefi: fs: Implement mkdir - Since there is no direct mkdir in UEFI, first check if a file/dir with same path exists and then create the directory. cc `@dvdhrm` `@nicholasbishop`
2025-03-19Auto merge of #138653 - matthiaskrgr:rollup-fwwqmr7, r=matthiaskrgrbors-1/+1
Rollup of 7 pull requests Successful merges: - #136320 (exit: document interaction with C) - #138080 (Leave a breadcrumb towards bootstrap config documentation in `bootstrap.toml`) - #138301 (Implement `read_buf` for Hermit) - #138569 (rustdoc-json: Add tests for `#[repr(...)]`) - #138635 (Extract `for_each_immediate_subpat` from THIR pattern visitors) - #138642 (Unvacation myself) - #138644 (Add `#[cfg(test)]` for Transition in dfa in `rustc_transmute`) r? `@ghost` `@rustbot` modify labels: rollup
2025-03-18Windows: fix FileType PartialEq implementationChris Denton-18/+15
2025-03-18std: uefi: fs: Implement mkdirAyush Singh-4/+30
- Since there is no direct mkdir in UEFI, first check if a file/dir with same path exists and then create the directory. Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-03-18Rollup merge of #138301 - thaliaarchi:io-optional-methods/hermit, r=tgross35Matthias Krüger-1/+1
Implement `read_buf` for Hermit Following https://github.com/hermit-os/kernel/pull/1606, it is now safe to implement `Read::read_buf` for file descriptors on Hermit. cc ```@mkroening```
2025-03-18Auto merge of #135368 - Ayush1325:uefi-fs-2, r=jhpratt,nicholasbishopbors-2/+138
uefi: fs: Implement exists Also adds the initial file abstractions. The file opening algorithm is inspired from UEFI shell. It starts by classifying if the Path is Shell mapping, text representation of device path protocol, or a relative path and converts into an absolute text representation of device path protocol. After that, it queries all handles supporting EFI_SIMPLE_FILE_SYSTEM_PROTOCOL and opens the volume that matches the device path protocol prefix (similar to Windows drive). After that, it opens the file in the volume using the remaining pat. It also introduces OwnedDevicePath and BorrowedDevicePath abstractions to allow working with the base UEFI and Shell device paths efficiently. DevicePath in UEFI behaves like an a group of nodes laied out in the memory contiguously and thus can be modeled using iterators. This is an effort to break the original PR (https://github.com/rust-lang/rust/pull/129700) into much smaller chunks for faster upstreaming.
2025-03-18uefi: fs: Implement existsAyush Singh-2/+138
Also adds the initial file abstractions. The file opening algorithm is inspired from UEFI shell. It starts by classifying if the Path is Shell mapping, text representation of device path protocol, or a relative path and converts into an absolute text representation of device path protocol. After that, it queries all handles supporting EFI_SIMPLE_FILE_SYSTEM_PROTOCOL and opens the volume that matches the device path protocol prefix (similar to Windows drive). After that, it opens the file in the volume using the remaining pat. It also introduces OwnedDevicePath and BorrowedDevicePath abstractions to allow working with the base UEFI and Shell device paths efficiently. DevicePath in UEFI behaves like an a group of nodes laied out in the memory contiguously and thus can be modeled using iterators. Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-03-17Implement read_buf for HermitThalia Archibald-1/+1
2025-03-17Rollup merge of #137621 - Berrysoft:cygwin-std, r=joboetJacob Pratt-1/+10
Add std support to cygwin target
2025-03-12Rollup merge of #138269 - Ayush1325:uefi-fs-permission, r=joboetMatthias Krüger-64/+35
uefi: fs: Implement FileType, FilePermissions and FileAttr - In UEFI, both FileType and FilePermissions are represented by the attr bitfield. - Using simple bools here since both are represented by a single bit. - Add `FILE_PERMISSION` mask for constructing attribute while change permissions. cc ````@nicholasbishop````
2025-03-11Rollup merge of #138002 - 1c3t3a:fix-std-cfi-violation, r=rcvalleMatthias Krüger-0/+14
Disable CFI for weakly linked syscalls Currently, when enabling CFI via -Zsanitizer=cfi and executing e.g. std::sys::random::getrandom, we can observe a CFI violation. This is the case for all consumers of the std::sys::pal::weak::syscall macro, as it is defining weak functions which don't show up in LLVM IR metadata. CFI fails for all these functions. Similar to other such cases in https://github.com/rust-lang/rust/issues/115199, this change stops emitting the CFI typecheck for consumers of the macro via the `#[no_sanitize(cfi)]` attribute. r? ``````@rcvalle``````
2025-03-10Fix code style王宇逸-1/+6
2025-03-10Initial STD support for Cygwin王宇逸-1/+5
Signed-off-by: Ookiineko <chiisaineko@protonmail.com>
2025-03-10Add comments for #[no_sanitize(cfi)] in stdlibBastian Kersting-0/+2
2025-03-10Disable CFI for weakly linked syscallsBastian Kersting-0/+12
Currently, when enabling CFI via -Zsanitizer=cfi and executing e.g. std::sys::random::getrandom, we can observe a CFI violation. This is the case for all consumers of the std::sys::pal::weak::weak macro, as it is defining weak functions which don't show up in LLVM IR metadata. CFI fails for all these functions. Similar to other such cases in https://github.com/rust-lang/rust/issues/115199, this change stops emitting the CFI typecheck for consumers of the macro via the \#[no_sanitize(cfi)] attribute.
2025-03-10uefi: fs: Partially implement FileAttrAyush Singh-15/+11
- Just the permission and file type. - FileTimes will need some new conversion functions and thus will come with a future PR. Trying to keep things simple here. Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-03-10uefi: fs: Implement FileTypeAyush Singh-30/+10
- Similar to FilePermissions, using bool to represent the bitfield. - FileType cannot be changed, so no need to worry about converting back to attribute. Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-03-10uefi: fs: Implement FilePermissionAyush Singh-21/+16
- UEFI file permissions are indicated using a u64 bitfield used for readonly/filetype, etc. - Using normal bool with to and from attribute conversions to FilePermission from overriding some other bitfields. Signed-off-by: Ayush Singh <ayush@beagleboard.org>