about summary refs log tree commit diff
path: root/library/std/src/sys/windows/fs.rs
AgeCommit message (Collapse)AuthorLines
2023-03-17Modify code style as per commentsNagaChaitanya Vellanki-7/+5
2023-03-16run rustfmt on changesNagaChaitanya Vellanki-1/+1
2023-03-16fallback to lstat when stat fails on WindowsNagaChaitanya Vellanki-1/+13
2023-02-13Add another error to Windows file open fallbackalesito85-1/+6
Added another error to be processed in fallback Solution suggested by Chris Denton https://github.com/nushell/nushell/issues/6857#issuecomment-1426847135
2023-02-10Zero the `REPARSE_MOUNTPOINT_DATA_BUFFER` headerChris Denton-0/+2
Makes sure the full header is correctly initialized, including reserve parameters.
2022-11-18Handle the case that even the filename array is unaligned.Thom Chiovoloni-5/+14
2022-11-17Don't assume `FILE_ID_BOTH_DIR_INFO` will be alignedThom Chiovoloni-5/+9
2022-10-01`SetFileTime` doesn't allow setting the file time to `0xFFFF_FFFF_FFFF_FFFF`beetrees-0/+8
2022-09-06Fix compile errors for uwp-windows-msvc targetsChris Denton-1/+1
2022-09-01Use `FILE_ATTRIBUTE_TAG_INFO` to get reparse tagChris Denton-8/+18
This avoid unnecessarily getting the full reparse data when all we need is the tag.
2022-08-31Avoid needless buffer zeroing in `std::sys::windows::fs`Thom Chiovoloni-14/+24
2022-08-30Fix UB in Windows `DirBuffIter` (provenance and alignment)Thom Chiovoloni-7/+10
2022-08-30Replace `AlignedAs` with a more specific `Align8` typeThom Chiovoloni-13/+14
2022-08-30Fix UWP and use `AlignedReparseBuf` in `symlink_junction_inner`Thom Chiovoloni-5/+6
2022-08-29Fix some possible UB in std::sys::windowsThom Chiovoloni-16/+24
2022-08-28Rollup merge of #97015 - nrc:read-buf-cursor, r=Mark-SimulacrumMatthias Krüger-3/+3
std::io: migrate ReadBuf to BorrowBuf/BorrowCursor This PR replaces `ReadBuf` (used by the `Read::read_buf` family of methods) with `BorrowBuf` and `BorrowCursor`. The general idea is to split `ReadBuf` because its API is large and confusing. `BorrowBuf` represents a borrowed buffer which is mostly read-only and (other than for construction) deals only with filled vs unfilled segments. a `BorrowCursor` is a mostly write-only view of the unfilled part of a `BorrowBuf` which distinguishes between initialized and uninitialized segments. For `Read::read_buf`, the caller would create a `BorrowBuf`, then pass a `BorrowCursor` to `read_buf`. In addition to the major API split, I've made the following smaller changes: * Removed some methods entirely from the API (mostly the functionality can be replicated with two calls rather than a single one) * Unified naming, e.g., by replacing initialized with init and assume_init with set_init * Added an easy way to get the number of bytes written to a cursor (`written` method) As well as simplifying the API (IMO), this approach has the following advantages: * Since we pass the cursor by value, we remove the 'unsoundness footgun' where a malicious `read_buf` could swap out the `ReadBuf`. * Since `read_buf` cannot write into the filled part of the buffer, we prevent the filled part shrinking or changing which could cause underflow for the caller or unexpected behaviour. ## Outline ```rust pub struct BorrowBuf<'a> impl Debug for BorrowBuf<'_> impl<'a> From<&'a mut [u8]> for BorrowBuf<'a> impl<'a> From<&'a mut [MaybeUninit<u8>]> for BorrowBuf<'a> impl<'a> BorrowBuf<'a> { pub fn capacity(&self) -> usize pub fn len(&self) -> usize pub fn init_len(&self) -> usize pub fn filled(&self) -> &[u8] pub fn unfilled<'this>(&'this mut self) -> BorrowCursor<'this, 'a> pub fn clear(&mut self) -> &mut Self pub unsafe fn set_init(&mut self, n: usize) -> &mut Self } pub struct BorrowCursor<'buf, 'data> impl<'buf, 'data> BorrowCursor<'buf, 'data> { pub fn clone<'this>(&'this mut self) -> BorrowCursor<'this, 'data> pub fn capacity(&self) -> usize pub fn written(&self) -> usize pub fn init_ref(&self) -> &[u8] pub fn init_mut(&mut self) -> &mut [u8] pub fn uninit_mut(&mut self) -> &mut [MaybeUninit<u8>] pub unsafe fn as_mut(&mut self) -> &mut [MaybeUninit<u8>] pub unsafe fn advance(&mut self, n: usize) -> &mut Self pub fn ensure_init(&mut self) -> &mut Self pub unsafe fn set_init(&mut self, n: usize) -> &mut Self pub fn append(&mut self, buf: &[u8]) } ``` ## TODO * ~~Migrate non-unix libs and tests~~ * ~~Naming~~ * ~~`BorrowBuf` or `BorrowedBuf` or `SliceBuf`? (We might want an owned equivalent for the async IO traits)~~ * ~~Should we rename the `readbuf` module? We might keep the name indicate it includes both the buf and cursor variations and someday the owned version too. Or we could change it. It is not publicly exposed, so it is not that important~~. * ~~`read_buf` method: we read into the cursor now, so the `_buf` suffix is a bit weird.~~ * ~~Documentation~~ * Tests are incomplete (I adjusted existing tests, but did not add new ones). cc https://github.com/rust-lang/rust/issues/78485, https://github.com/rust-lang/rust/issues/94741 supersedes: https://github.com/rust-lang/rust/pull/95770, https://github.com/rust-lang/rust/pull/93359 fixes #93305
2022-08-21Replace most uses of `pointer::offset` with `add` and `sub`Maybe Waffle-3/+3
2022-08-18Address reviewer commentsNick Cameron-1/+1
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-08-05non-linux platformsNick Cameron-3/+3
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-08-01Auto merge of #98246 - joshtriplett:times, r=m-ou-sebors-0/+31
Support setting file accessed/modified timestamps Add `struct FileTimes` to contain the relevant file timestamps, since most platforms require setting all of them at once. (This also allows for future platform-specific extensions such as setting creation time.) Add `File::set_file_time` to set the timestamps for a `File`. Implement the `sys` backends for UNIX, macOS (which needs to fall back to `futimes` before macOS 10.13 because it lacks `futimens`), Windows, and WASI.
2022-07-30Reset directory iteration in remove_dir_allChris Denton-1/+3
2022-07-15Return an error if trying to set a file timestamp to 0 on WindowsJosh Triplett-5/+12
This would otherwise silently ignore the attempt, since 0 serves as a flag to not set a timestamp.
2022-07-15Support setting file accessed/modified timestampsJosh Triplett-0/+24
Add `struct FileTimes` to contain the relevant file timestamps, since most platforms require setting all of them at once. (This also allows for future platform-specific extensions such as setting creation time.) Add `File::set_file_time` to set the timestamps for a `File`. Implement the `sys` backends for UNIX, macOS (which needs to fall back to `futimes` before macOS 10.13 because it lacks `futimens`), Windows, and WASI.
2022-07-05Windows: Use `FindFirstFileW` if `metadata` failsChris Denton-10/+61
Usually opening a file handle with access set to metadata only will always succeed, even if the file is locked. However some special system files, such as `C:\hiberfil.sys`, are locked by the system in a way that denies even that. So as a fallback we try reading the cached metadata from the directory.
2022-07-05`impl From<c::WIN32_FIND_DATAW> for FileAttr`Chris Denton-16/+21
2022-06-25Rollup merge of #96412 - ChrisDenton:remove-dir-all, r=thomccMatthias Krüger-75/+81
Windows: Iterative `remove_dir_all` This will allow better strategies for use of memory and File handles. However, fully taking advantage of that is left to future work. Note to reviewer: It's probably best to view the `remove_dir_all_recursive` as a new function. The diff is not very helpful (imho).
2022-05-09Use Rust 2021 prelude in std itself.Mara Bos-1/+0
2022-04-28Yield the thread when waiting to delete a fileChris Denton-0/+3
2022-04-26Retry deleting a directoryChris Denton-2/+15
It's possible that a file in the directory is pending deletion. In that case we might succeed after a few attempts.
2022-04-26Windows: Iterative `remove_dir_all`Chris Denton-77/+67
This will allow better strategies for use of memory and File handles. However, fully taking advantage of that is left to future work.
2022-03-29Make the stdlib largely conform to strict provenance.Aria Beingessner-4/+7
Some things like the unwinders and system APIs are not fully conformant, this only covers a lot of low-hanging fruit.
2022-03-03Use `HandleOrNull` and `HandleOrInvalid` in the Windows FFI bindings.Dan Gohman-3/+4
Use the new `HandleOrNull` and `HandleOrInvalid` types that were introduced as part of [I/O safety] in a few functions in the Windows FFI bindings. This factors out an `unsafe` block and two `unsafe` function calls in the Windows implementation code. And, it helps test `HandleOrNull` and `HandleOrInvalid`, which indeed turned up a bug: `OwnedHandle` also needs to be `#[repr(transparent)]`, as it's used inside of `HandleOrNull` and `HandleOrInvalid` which are also `#[repr(transparent)]`. [I/O safety]: https://github.com/rust-lang/rust/issues/87074
2022-02-08Rollup merge of #93206 - ChrisDenton:ntopenfile, r=nagisaMatthias Krüger-3/+8
Use `NtCreateFile` instead of `NtOpenFile` to open a file Generally the internal `Nt*` functions should be avoided but when we do need to use one we should stick to the most commonly used for the job. To that end, this PR replaces `NtOpenFile` with `NtCreateFile`. NOTE: The initial version of this comment hypothesised that this may help with some recent false positives from malware scanners. This hypothesis proved wrong. Sorry for the distraction.
2022-02-04Hide Repr details from io::Error, and rework `io::Error::new_const`.Thom Chiovoloni-4/+4
2022-01-25Rollup merge of #88794 - sunfishcode:sunfishcode/try-clone, r=joshtriplettMatthias Krüger-1/+1
Add a `try_clone()` function to `OwnedFd`. As suggested in #88564. This adds a `try_clone()` to `OwnedFd` by refactoring the code out of the existing `File`/`Socket` code. r? ``@joshtriplett``
2022-01-24Use `NtCreateFile` instead of `NtOpenFile` to open a fileChris Denton-3/+8
2022-01-19Fix CVE-2022-21658 for WindowsChris Denton-17/+305
2021-11-02more efficent File::read_buf impl for windows and unixDrMeepster-1/+5
2021-10-30Auto merge of #89174 - ChrisDenton:automatic-verbatim-paths, r=dtolnaybors-13/+14
Automatically convert paths to verbatim for filesystem operations that support it This allows using longer paths without the user needing to `canonicalize` or manually prefix paths. If the path is already verbatim then this has no effect. Fixes: #32689
2021-10-09Apply clippy suggestionsClemens Wasser-2/+2
2021-10-03Automatically convert paths to verbatimChris Denton-13/+14
This allows using longer paths for filesystem operations without the user needing to `canonicalize` or manually prefix paths. If the path is already verbatim than this has no effect.
2021-09-09Fix Windows compilation errors.Dan Gohman-1/+1
2021-09-09Add a `try_clone()` function to `OwnedFd`.Dan Gohman-1/+1
As suggested in #88564. This adds a `try_clone()` to `OwnedFd` by refactoring the code out of the existing `File`/`Socket` code.
2021-09-02I/O safety for WinUWPbdbai-2/+2
2021-08-19I/O safety.Dan Gohman-22/+51
Introduce `OwnedFd` and `BorrowedFd`, and the `AsFd` trait, and implementations of `AsFd`, `From<OwnedFd>` and `From<T> for OwnedFd` for relevant types, along with Windows counterparts for handles and sockets. Tracking issue: - <https://github.com/rust-lang/rust/issues/87074> RFC: - <https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md>
2021-06-15Rename ErrorKind::Unknown to Uncategorized.Mara Bos-1/+1
2021-06-15Redefine `ErrorKind::Other` and stop using it in std.Mara Bos-4/+3
2021-05-19Windows implementation of `fs::try_exists`Chris Denton-1/+29
2021-05-19Move the implementation of `Path::exists` to `sys_common::fs` so platforms ↵Chris Denton-0/+1
can specialize it Windows implementation of `fs::try_exists`
2021-04-18Rename `NotSupported` to `Unsupported`Christiaan Dirkx-1/+4