about summary refs log tree commit diff
path: root/src/libstd/sys/unix/fs.rs
AgeCommit message (Collapse)AuthorLines
2019-04-19Fix sync_all on macos/iosDavid Vázquez Púa-2/+9
sync_all should flush all metadata in macos/ios, so it should call fcntl with the F_FULLFSYNC flag as sync_data does. Fixes #55920
2019-04-10std: Add `{read,write}_vectored` for more typesAlex Crichton-1/+9
This commit implements the `{read,write}_vectored` methods on more types in the standard library, namely: * `std::fs::File` * `std::process::ChildStd{in,out,err}` * `std::io::Std{in,out,err}` * `std::io::Std{in,out,err}Lock` * `std::io::Std{in,out,err}Raw` Where supported the OS implementations hook up to native support, otherwise it falls back to the already-defaulted implementation.
2019-04-03wasi: Fill out `std::fs` module for WASIAlex Crichton-21/+2
This commit fills out the `std::fs` module and implementation for WASI. Not all APIs are implemented, such as permissions-related ones and `canonicalize`, but all others APIs have been implemented and very lightly tested so far. We'll eventually want to run a more exhaustive test suite! For now the highlights of this commit are: * The `std::fs::File` type is now backed by `WasiFd`, a raw WASI file descriptor. * All APIs in `std::fs` (except permissions/canonicalize) have implementations for the WASI target. * A suite of unstable extension traits were added to `std::os::wasi::fs`. These traits expose the raw filesystem functionality of WASI, namely `*at` syscalls (opening a file relative to an already opened one, for example). Additionally metadata only available on wasi is exposed through these traits. Perhaps one of the most notable parts is the implementation of path-taking APIs. WASI actually has no fundamental API that just takes a path, but rather everything is relative to a previously opened file descriptor. To allow existing APIs to work (that only take a path) WASI has a few syscalls to learn about "pre opened" file descriptors by the runtime. We use these to build a map of existing directory names to file descriptors, and then when using a path we try to anchor it at an already-opened file. This support is very rudimentary though and is intended to be shared with C since it's likely to be so tricky. For now though the C library doesn't expose quite an API for us to use, so we implement it for now and will swap it out as soon as one is available.
2019-03-31libstd: deny(elided_lifetimes_in_paths)Mazdak Farrokhzad-2/+2
2019-03-23fs::copy() set file mode earlyHarald Hoyer-55/+74
A convenience method like fs::copy() should try to prevent pitfalls a normal user doesn't think about. In case of an empty umask, setting the file mode early prevents temporarily world readable or even writeable files, because the default mode is 0o666. In case the target is a named pipe or special device node, setting the file mode can lead to unwanted side effects, like setting permissons on `/dev/stdout` or for root setting permissions on `/dev/null`. copy_file_range() returns EINVAL, if the destination is a FIFO/pipe or a device like "/dev/null", so fallback to io::copy, too. Use `fcopyfile` on MacOS instead of `copyfile`. Fixes: https://github.com/rust-lang/rust/issues/26933 Fixed: https://github.com/rust-lang/rust/issues/37885
2019-03-04Change `std::fs::copy` to use `copyfile` on MacOS and iOSEdward Barnard-1/+86
2019-02-28libstd => 2018Taiki Endo-24/+28
2018-12-25Remove licensesMark Rousskov-10/+0
2018-11-06refactor: use shorthand fieldsteresy-4/+4
2018-08-19Fix typos found by codespell.Matthias Krüger-1/+1
2018-07-30Add targets for HermitCore (https://hermitcore.org) to the Rust compiler and ↵Colin Finck-4/+6
port libstd to it. As a start, the port uses the simplest possible configuration (no jemalloc, abort on panic) and makes use of existing Unix-specific code wherever possible. It adds targets for x86_64 (current main HermitCore platform) and aarch64 (HermitCore platform under development). Together with the patches to "liblibc" and "llvm", this enables HermitCore applications to be written in Rust.
2018-06-26Rollup merge of #51786 - cuviper:stat64-pointers, r=Mark-SimulacrumPietro Albini-2/+2
Remove unnecessary stat64 pointer casts In effect, these just casted `&mut stat64` to `*mut stat64`, twice. That's harmless, but it masked a problem when this was copied to new code calling `fstatat`, which takes a pointer to `struct stat`. That will be fixed by #51785, but let's remove the unnecessary casts here too.
2018-06-26Auto merge of #50630 - sharkdp:fix-50619, r=sfacklerbors-7/+24
Fix possibly endless loop in ReadDir iterator Certain directories in `/proc` can cause the `ReadDir` iterator to loop indefinitely. We get an error code (22) when calling libc's `readdir_r` on these directories, but `entry_ptr` is `NULL` at the same time, signalling the end of the directory stream. This change introduces an internal state to the iterator such that the `Some(Err(..))` value will only be returned once when calling `next`. Subsequent calls will return `None`. fixes #50619
2018-06-25Remove unnecessary stat64 pointer castsJosh Stone-2/+2
In effect, these just casted `&mut stat64` to `*mut stat64`, twice. That's harmless, but it masked a problem when this was copied to new code calling `fstatat`, which takes a pointer to `struct stat`. That will be fixed by #51785, but let's remove the unnecessary casts here too.
2018-06-25Use fstatat64 where availableJosh Stone-6/+5
2018-06-12Fix possibly endless loop in ReadDir iteratorsharkdp-7/+24
Certain directories in `/proc` can cause the `ReadDir` iterator to loop indefinitely. We get an error code (22) when calling libc's `readdir_r` on these directories, but `entry_ptr` is `NULL` at the same time, signalling the end of the directory stream. This change introduces an internal state to the iterator such that the `Some(Err(..))` value will only be returned once when calling `next`. Subsequent calls will return `None`. fixes #50619
2018-06-01fs: copy: Add EPERM to fallback error conditionsNicolas Koch-5/+12
Fixes #51266
2018-05-31Rollup merge of #51213 - nicokoch:copy_permissions, r=cramertjGuillaume Gomez-5/+5
fs: copy: Use File::set_permissions instead of fs::set_permissions We already got the open file descriptor at this point. Don't make the kernel resolve the path again.
2018-05-31libstd/sys/unix/fs.rs: fix compilation on fuchsiaGuillaume Girol-1/+1
2018-05-30std::fs::DirEntry.metadata(): use fstatat instead of lstat when possibleGuillaume Girol-11/+32
2018-05-30Remobve unused importNicolas Koch-1/+1
2018-05-30fs: copy: Use File::set_permissions instead of fs::set_permissionsNicolas Koch-4/+4
We already got the open file descriptor at this point. Don't make the kernel resolve the path again.
2018-05-29Auto merge of #50772 - nicokoch:fastcopy, r=alexcrichtonbors-0/+88
fs: copy: use copy_file_range on Linux Linux 4.5 introduced a new system call [copy_file_range](http://man7.org/linux/man-pages/man2/copy_file_range.2.html) to copy data from one file to another. This PR uses the new system call (if available). This has several advantages: 1. No need to constantly copy data from userspace to kernel space, if the buffer is small or the file is large 2. On some filesystems, like BTRFS, the kernel can leverage internal fs mechanisms for huge performance gains 3. Filesystems on the network dont need to copy data between the host and the client machine (they have to in the current read/write implementation) I have created a small library that also implements the new system call for some huge performance gains here: https://github.com/nicokoch/fastcopy Benchmark results are in the README
2018-05-29Fix additional nits:Nicolas Koch-7/+3
- compute bytes_to_copy more elegantly - add assert that written is 0 in fallback case
2018-05-28Use FIXME instead of TODO; Move bytes_to_copy calculation inside ifNicolas Koch-6/+7
branch
2018-05-24Implement suggestions from the PRNicolas Koch-1/+3
- Move loading of atomic bool outside the loop - Add comment about TryFrom for future improvement
2018-05-17Store ENOSYS in a global to avoid unnecessary system callsNicolas Koch-10/+25
2018-05-16Fix large file copies on 32 bit platformsNicolas Koch-2/+6
2018-05-16Adjust len in every iterationNicolas Koch-1/+2
2018-05-16Add clarifying comment about offset argumentNicolas Koch-0/+2
2018-05-16Use copy_file_range on android alsoNicolas Koch-3/+3
2018-05-15fs: use copy_file_range on linuxNicolas Koch-0/+67
2018-05-14Don't unconditionally set CLOEXEC twice on every fd we open on LinuxTobias Bucher-4/+37
Previously, every `open64` was accompanied by a `ioctl(…, FIOCLEX)`, because some old Linux version would ignore the `O_CLOEXEC` flag we pass to the `open64` function. Now, we check whether the `CLOEXEC` flag is set on the first file we open – if it is, we won't do extra syscalls for every opened file. If it is not set, we fall back to the old behavior of unconditionally calling `ioctl(…, FIOCLEX)` on newly opened files. On old Linuxes, this amounts to one extra syscall per process, namely the `fcntl(…, F_GETFD)` call to check the `CLOEXEC` flag. On new Linuxes, this reduces the number of syscalls per opened file by one, except for the first file, where it does the same number of syscalls as before (`fcntl(…, F_GETFD)` to check the flag instead of `ioctl(…, FIOCLEX)` to set it).
2017-10-20Fix some tests for linux gnux32Marco A L Barbosa-2/+2
2017-09-17Remove st_mode maskTrevor Merrifield-1/+1
2017-09-15Retain suid/sgid/sticky bits in Metadata.permissionsTrevor Merrifield-1/+1
Most users would expect set_permissions(Metadata.permissions()) to be non-destructive. While we can't guarantee this, we can at least pass the needed info to chmod. Also update the PermissionsExt documentation to disambiguate what it contains, and to refer to the underlying value as `st_mode` rather than its type `mode_t`. Closes #44147
2017-09-08Add modifications needed for L4re in libstdTobias Schaffner-1/+5
This commit adds the needed modifications to compile the std crate for the L4 Runtime environment (L4Re). A target for the L4Re was introduced in commit: c151220a84e40b65e45308cc0f3bbea4466d3acf In many aspects implementations for linux also apply for the L4Re microkernel. Two uncommon characteristics had to be resolved: * L4Re has no network funktionality * L4Re has a maximum stacksize of 1Mb for threads Co-authored-by: Sebastian Humenda <sebastian.humenda@tu-dresden.de>
2017-08-28Update the libc submoduleAlex Crichton-0/+2
Brings in a few fixes for wasm/asmjs
2017-08-15Add comments clarifying behavior of unix `set_readonly` behavior.Corey Farwell-1/+7
2017-08-03Fix a dangling symlink bug in `remove_dir_all()` on SolarisDanek Duvall-6/+1
This fixes a handful of long-failing tests.
2017-06-20Add `Read::initializer`.Steven Fackler-4/+0
This is an API that allows types to indicate that they can be passed buffers of uninitialized memory which can improve performance.
2017-03-12Update usages of 'OSX' (and other old names) to 'macOS'.Corey Farwell-2/+2
As of last year with version 'Sierra', the Mac operating system is now called 'macOS'.
2017-02-22Update name_bytes, scoop up latest libcRaph Levien-3/+3
Update the implementation of name_bytes to use the owned string (which is thread safe). Also bump the src/liblibc submodule now that's merged.
2017-02-21Switch Fuchsia to readdir (instead of readdir_r)Raph Levien-10/+11
The readdir_r function is deprecated on newer Posix systems because of various problems, and not implemented at all for Fuchsia. There are already implementations using both, and this patch switches Fuchsia over to the readdir-based one. Fixes #40021 for Fuchsia, but that issue also contains discussion of what should happen for other Posix systems.
2016-12-18Implement `fmt::Debug` for all structures in libstd.Corey Farwell-1/+2
Part of https://github.com/rust-lang/rust/issues/31869. Also turn on the `missing_debug_implementations` lint at the crate level.
2016-11-22Add a method for setting permissions directly on an open file.Steven Allen-0/+5
On unix like systems, the underlying file corresponding to any given path may change at any time. This function makes it possible to set the permissions of the a file corresponding to a `File` object even if its path changes.
2016-10-22Fix missing DirEntryExt::inoRaph Levien-1/+2
The DirEntryExt::ino() implementation was omitted from the first iteration of this patch, because a dependency needed to be configured. The fix is straightforward enough.
2016-10-22Add Fuchsia supportRaph Levien-1/+2
Adds support for the x86_64-unknown-fuchsia target, which covers the Fuchsia operating system.
2016-10-16impl Debug for ReadDirDavid Henningsson-0/+8
It is good practice to implement Debug for public types, and indicating what directory you're reading seems useful. Signed-off-by: David Henningsson <diwic@ubuntu.com>
2016-10-09Implement reading and writing atomically at certain offsetsTobias Bucher-0/+8
These functions allow to read from and write to a file in one atomic action from multiple threads, avoiding the race between the seek and the read. The functions are named `{read,write}_at` on non-Windows (which don't change the file cursor), and `seek_{read,write}` on Windows (which change the file cursor).