Skip to content

Commit 432a23f

Browse files
committed
Move fs into sys
1 parent d58c42b commit 432a23f

File tree

28 files changed

+70
-55
lines changed

28 files changed

+70
-55
lines changed
File renamed without changes.

library/std/src/sys/pal/hermit/fs.rs library/std/src/sys/fs/hermit.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
use super::fd::FileDesc;
2-
use super::hermit_abi::{
3-
self, DT_DIR, DT_LNK, DT_REG, DT_UNKNOWN, O_APPEND, O_CREAT, O_DIRECTORY, O_EXCL, O_RDONLY,
4-
O_RDWR, O_TRUNC, O_WRONLY, S_IFDIR, S_IFLNK, S_IFMT, S_IFREG, dirent64, stat as stat_struct,
5-
};
61
use crate::ffi::{CStr, OsStr, OsString, c_char};
72
use crate::io::{self, BorrowedCursor, Error, ErrorKind, IoSlice, IoSliceMut, SeekFrom};
83
use crate::os::hermit::ffi::OsStringExt;
4+
use crate::os::hermit::hermit_abi::{
5+
self, DT_DIR, DT_LNK, DT_REG, DT_UNKNOWN, O_APPEND, O_CREAT, O_DIRECTORY, O_EXCL, O_RDONLY,
6+
O_RDWR, O_TRUNC, O_WRONLY, S_IFDIR, S_IFLNK, S_IFMT, S_IFREG, dirent64, stat as stat_struct,
7+
};
98
use crate::os::hermit::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd};
109
use crate::path::{Path, PathBuf};
1110
use crate::sync::Arc;
1211
use crate::sys::common::small_c_string::run_path_with_cstr;
12+
pub use crate::sys::fs::common::{copy, exists};
13+
use crate::sys::pal::fd::FileDesc;
1314
use crate::sys::time::SystemTime;
1415
use crate::sys::{cvt, unsupported};
15-
pub use crate::sys_common::fs::{copy, exists};
1616
use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
1717
use crate::{fmt, mem};
1818

library/std/src/sys/fs/mod.rs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#![deny(unsafe_op_in_unsafe_fn)]
2+
3+
pub mod common;
4+
5+
cfg_if::cfg_if! {
6+
if #[cfg(target_family = "unix")] {
7+
mod unix;
8+
pub use unix::*;
9+
} else if #[cfg(target_os = "windows")] {
10+
mod windows;
11+
pub use windows::*;
12+
} else if #[cfg(target_os = "hermit")] {
13+
mod hermit;
14+
pub use hermit::*;
15+
} else if #[cfg(target_os = "solid_asp3")] {
16+
mod solid;
17+
pub use solid::*;
18+
} else if #[cfg(target_os = "uefi")] {
19+
mod uefi;
20+
pub use uefi::*;
21+
} else if #[cfg(target_os = "wasi")] {
22+
mod wasi;
23+
pub use wasi::*;
24+
} else {
25+
mod unsupported;
26+
pub use unsupported::*;
27+
}
28+
}

library/std/src/sys/pal/solid/fs.rs library/std/src/sys/fs/solid.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use super::{abi, error};
1+
#![allow(dead_code)]
2+
23
use crate::ffi::{CStr, CString, OsStr, OsString};
34
use crate::fmt;
45
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut, SeekFrom};
@@ -7,9 +8,10 @@ use crate::os::raw::{c_int, c_short};
78
use crate::os::solid::ffi::OsStrExt;
89
use crate::path::{Path, PathBuf};
910
use crate::sync::Arc;
11+
pub use crate::sys::fs::common::exists;
12+
use crate::sys::pal::{abi, error};
1013
use crate::sys::time::SystemTime;
1114
use crate::sys::unsupported;
12-
pub use crate::sys_common::fs::exists;
1315
use crate::sys_common::ignore_notfound;
1416

1517
type CIntNotMinusOne = core::num::niche_types::NotAllOnes<c_int>;
File renamed without changes.

library/std/src/sys/pal/unix/fs.rs library/std/src/sys/fs/unix.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(nonstandard_style)]
2+
#![allow(unsafe_op_in_unsafe_fn)]
13
// miri has some special hacks here that make things unused.
24
#![cfg_attr(miri, allow(unused))]
35

@@ -79,13 +81,13 @@ use crate::path::{Path, PathBuf};
7981
use crate::sync::Arc;
8082
use crate::sys::common::small_c_string::run_path_with_cstr;
8183
use crate::sys::fd::FileDesc;
84+
pub use crate::sys::fs::common::exists;
8285
use crate::sys::time::SystemTime;
8386
#[cfg(all(target_os = "linux", target_env = "gnu"))]
8487
use crate::sys::weak::syscall;
8588
#[cfg(target_os = "android")]
8689
use crate::sys::weak::weak;
8790
use crate::sys::{cvt, cvt_r};
88-
pub use crate::sys_common::fs::exists;
8991
use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
9092
use crate::{mem, ptr};
9193

@@ -699,6 +701,8 @@ impl Iterator for ReadDir {
699701
target_os = "hurd",
700702
))]
701703
fn next(&mut self) -> Option<io::Result<DirEntry>> {
704+
use crate::sys::os::{errno, set_errno};
705+
702706
if self.end_of_stream {
703707
return None;
704708
}
@@ -710,7 +714,7 @@ impl Iterator for ReadDir {
710714
// with unlimited or variable NAME_MAX. Many modern platforms guarantee
711715
// thread safety for readdir() as long an individual DIR* is not accessed
712716
// concurrently, which is sufficient for Rust.
713-
super::os::set_errno(0);
717+
set_errno(0);
714718
let entry_ptr: *const dirent64 = readdir64(self.inner.dirp.0);
715719
if entry_ptr.is_null() {
716720
// We either encountered an error, or reached the end. Either way,
@@ -719,7 +723,7 @@ impl Iterator for ReadDir {
719723

720724
// To distinguish between errors and end-of-directory, we had to clear
721725
// errno beforehand to check for an error now.
722-
return match super::os::errno() {
726+
return match errno() {
723727
0 => None,
724728
e => Some(Err(Error::from_raw_os_error(e))),
725729
};
@@ -1932,7 +1936,7 @@ pub fn canonicalize(p: &Path) -> io::Result<PathBuf> {
19321936

19331937
fn open_from(from: &Path) -> io::Result<(crate::fs::File, crate::fs::Metadata)> {
19341938
use crate::fs::File;
1935-
use crate::sys_common::fs::NOT_FILE_ERROR;
1939+
use crate::sys::fs::common::NOT_FILE_ERROR;
19361940

19371941
let reader = File::open(from)?;
19381942
let metadata = reader.metadata()?;
@@ -2151,7 +2155,7 @@ pub use remove_dir_impl::remove_dir_all;
21512155
miri
21522156
))]
21532157
mod remove_dir_impl {
2154-
pub use crate::sys_common::fs::remove_dir_all;
2158+
pub use crate::sys::fs::common::remove_dir_all;
21552159
}
21562160

21572161
// Modern implementation using openat(), unlinkat() and fdopendir()

library/std/src/sys/pal/unix/fs/tests.rs library/std/src/sys/fs/unix/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::sys::pal::unix::fs::FilePermissions;
1+
use crate::sys::fs::FilePermissions;
22

33
#[test]
44
fn test_debug_permissions() {

library/std/src/sys/pal/wasi/fs.rs library/std/src/sys/fs/wasi.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#![forbid(unsafe_op_in_unsafe_fn)]
2-
3-
use super::fd::WasiFd;
41
use crate::ffi::{CStr, OsStr, OsString};
52
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut, SeekFrom};
63
use crate::mem::{self, ManuallyDrop};
@@ -10,9 +7,10 @@ use crate::os::wasi::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd
107
use crate::path::{Path, PathBuf};
118
use crate::sync::Arc;
129
use crate::sys::common::small_c_string::run_path_with_cstr;
10+
use crate::sys::fd::WasiFd;
11+
pub use crate::sys::fs::common::exists;
1312
use crate::sys::time::SystemTime;
1413
use crate::sys::unsupported;
15-
pub use crate::sys_common::fs::exists;
1614
use crate::sys_common::{AsInner, FromInner, IntoInner, ignore_notfound};
1715
use crate::{fmt, iter, ptr};
1816

library/std/src/sys/pal/windows/fs.rs library/std/src/sys/fs/windows.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use super::api::{self, WinError, set_file_information_by_handle};
2-
use super::{IoResult, to_u16s};
1+
#![allow(nonstandard_style)]
2+
33
use crate::alloc::{alloc, handle_alloc_error};
44
use crate::borrow::Cow;
55
use crate::ffi::{OsStr, OsString, c_void};
@@ -10,6 +10,8 @@ use crate::os::windows::prelude::*;
1010
use crate::path::{Path, PathBuf};
1111
use crate::sync::Arc;
1212
use crate::sys::handle::Handle;
13+
use crate::sys::pal::api::{self, WinError, set_file_information_by_handle};
14+
use crate::sys::pal::{IoResult, fill_utf16_buf, to_u16s, truncate_utf16_at_nul};
1315
use crate::sys::path::maybe_verbatim;
1416
use crate::sys::time::SystemTime;
1517
use crate::sys::{Align8, c, cvt};
@@ -167,7 +169,7 @@ impl DirEntry {
167169
}
168170

169171
pub fn file_name(&self) -> OsString {
170-
let filename = super::truncate_utf16_at_nul(&self.data.cFileName);
172+
let filename = truncate_utf16_at_nul(&self.data.cFileName);
171173
OsString::from_wide(filename)
172174
}
173175

@@ -695,7 +697,7 @@ impl File {
695697
// Turn `\??\` into `\\?\` (a verbatim path).
696698
subst[1] = b'\\' as u16;
697699
// Attempt to convert to a more user-friendly path.
698-
let user = super::args::from_wide_to_user_path(
700+
let user = crate::sys::args::from_wide_to_user_path(
699701
subst.iter().copied().chain([0]).collect(),
700702
)?;
701703
Ok(PathBuf::from(OsString::from_wide(user.strip_suffix(&[0]).unwrap_or(&user))))
@@ -1562,7 +1564,7 @@ pub fn set_perm(p: &Path, perm: FilePermissions) -> io::Result<()> {
15621564
}
15631565

15641566
fn get_path(f: &File) -> io::Result<PathBuf> {
1565-
super::fill_utf16_buf(
1567+
fill_utf16_buf(
15661568
|buf, sz| unsafe {
15671569
c::GetFinalPathNameByHandleW(f.handle.as_raw_handle(), buf, sz, c::VOLUME_NAME_DOS)
15681570
},

library/std/src/sys/pal/windows/fs/remove_dir_all.rs library/std/src/sys/fs/windows/remove_dir_all.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use core::sync::atomic::{AtomicU32, Ordering};
3333

3434
use super::{AsRawHandle, DirBuff, File, FromRawHandle};
3535
use crate::sys::c;
36-
use crate::sys::pal::windows::api::WinError;
36+
use crate::sys::pal::api::WinError;
3737
use crate::thread;
3838

3939
// The maximum number of times to spin when waiting for deletes to complete.

library/std/src/sys/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub mod anonymous_pipe;
1212
pub mod backtrace;
1313
pub mod cmath;
1414
pub mod exit_guard;
15+
pub mod fs;
1516
pub mod io;
1617
pub mod net;
1718
pub mod os_str;

library/std/src/sys/pal/hermit/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use crate::os::raw::c_char;
2121
pub mod args;
2222
pub mod env;
2323
pub mod fd;
24-
pub mod fs;
2524
pub mod futex;
2625
pub mod os;
2726
#[path = "../unsupported/pipe.rs"]

library/std/src/sys/pal/sgx/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ pub mod abi;
1212
pub mod args;
1313
pub mod env;
1414
pub mod fd;
15-
#[path = "../unsupported/fs.rs"]
16-
pub mod fs;
1715
mod libunwind_integration;
1816
pub mod os;
1917
#[path = "../unsupported/pipe.rs"]

library/std/src/sys/pal/solid/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ pub mod env;
2222
// `error` is `pub(crate)` so that it can be accessed by `itron/error.rs` as
2323
// `crate::sys::error`
2424
pub(crate) mod error;
25-
pub mod fs;
2625
pub mod os;
2726
#[path = "../unsupported/pipe.rs"]
2827
pub mod pipe;

library/std/src/sys/pal/solid/time.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl SystemTime {
3535
SystemTime(t)
3636
}
3737

38-
pub(super) fn from_time_t(t: abi::time_t) -> Self {
38+
pub fn from_time_t(t: abi::time_t) -> Self {
3939
Self(t)
4040
}
4141

library/std/src/sys/pal/teeos/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ pub mod args;
1111
#[path = "../unsupported/env.rs"]
1212
pub mod env;
1313
//pub mod fd;
14-
#[path = "../unsupported/fs.rs"]
15-
pub mod fs;
1614
pub mod os;
1715
#[path = "../unsupported/pipe.rs"]
1816
pub mod pipe;

library/std/src/sys/pal/uefi/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
pub mod args;
1717
pub mod env;
18-
pub mod fs;
1918
pub mod helpers;
2019
pub mod os;
2120
#[path = "../unsupported/pipe.rs"]

library/std/src/sys/pal/unix/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ pub mod weak;
99
pub mod args;
1010
pub mod env;
1111
pub mod fd;
12-
pub mod fs;
1312
pub mod futex;
1413
#[cfg(any(target_os = "linux", target_os = "android"))]
1514
pub mod kernel_copy;

library/std/src/sys/pal/unsupported/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
pub mod args;
44
pub mod env;
5-
pub mod fs;
65
pub mod os;
76
pub mod pipe;
87
pub mod process;

library/std/src/sys/pal/wasi/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
pub mod args;
1717
pub mod env;
1818
pub mod fd;
19-
pub mod fs;
2019
#[allow(unused)]
2120
#[path = "../wasm/atomics/futex.rs"]
2221
pub mod futex;

library/std/src/sys/pal/wasip2/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ pub mod args;
1212
pub mod env;
1313
#[path = "../wasi/fd.rs"]
1414
pub mod fd;
15-
#[path = "../wasi/fs.rs"]
16-
pub mod fs;
1715
#[allow(unused)]
1816
#[path = "../wasm/atomics/futex.rs"]
1917
pub mod futex;

library/std/src/sys/pal/wasm/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#[path = "../unsupported/args.rs"]
2020
pub mod args;
2121
pub mod env;
22-
#[path = "../unsupported/fs.rs"]
23-
pub mod fs;
2422
#[path = "../unsupported/os.rs"]
2523
pub mod os;
2624
#[path = "../unsupported/pipe.rs"]

library/std/src/sys/pal/windows/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ pub mod api;
1717
pub mod args;
1818
pub mod c;
1919
pub mod env;
20-
pub mod fs;
2120
#[cfg(not(target_vendor = "win7"))]
2221
pub mod futex;
2322
pub mod handle;
@@ -37,7 +36,7 @@ cfg_if::cfg_if! {
3736
}
3837

3938
/// Map a [`Result<T, WinError>`] to [`io::Result<T>`](crate::io::Result<T>).
40-
trait IoResult<T> {
39+
pub trait IoResult<T> {
4140
fn io_result(self) -> crate::io::Result<T>;
4241
}
4342
impl<T> IoResult<T> for Result<T, api::WinError> {

library/std/src/sys/pal/xous/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
pub mod args;
44
#[path = "../unsupported/env.rs"]
55
pub mod env;
6-
#[path = "../unsupported/fs.rs"]
7-
pub mod fs;
86
pub mod os;
97
#[path = "../unsupported/pipe.rs"]
108
pub mod pipe;

library/std/src/sys/pal/zkvm/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ pub mod abi;
1414
#[path = "../zkvm/args.rs"]
1515
pub mod args;
1616
pub mod env;
17-
#[path = "../unsupported/fs.rs"]
18-
pub mod fs;
1917
pub mod os;
2018
#[path = "../unsupported/pipe.rs"]
2119
pub mod pipe;

library/std/src/sys_common/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#[cfg(test)]
2121
mod tests;
2222

23-
pub mod fs;
2423
pub mod process;
2524
pub mod wstr;
2625
pub mod wtf8;

src/tools/miri/tests/fail/shims/fs/isolated_file.stderr

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
error: unsupported operation: `open` not available when isolation is enabled
2-
--> RUSTLIB/std/src/sys/pal/PLATFORM/fs.rs:LL:CC
2+
--> RUSTLIB/std/src/sys/fs/PLATFORM.rs:LL:CC
33
|
44
LL | let fd = cvt_r(|| unsafe { open64(path.as_ptr(), flags, opts.mode as c_int) })?;
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `open` not available when isolation is enabled
66
|
77
= help: set `MIRIFLAGS=-Zmiri-disable-isolation` to disable isolation;
88
= help: or set `MIRIFLAGS=-Zmiri-isolation-error=warn` to make Miri return an error code from isolated operations (if supported for that operation) and continue with a warning
99
= note: BACKTRACE:
10-
= note: inside closure at RUSTLIB/std/src/sys/pal/PLATFORM/fs.rs:LL:CC
11-
= note: inside `std::sys::pal::PLATFORM::cvt_r::<i32, {closure@std::sys::pal::PLATFORM::fs::File::open_c::{closure#0}}>` at RUSTLIB/std/src/sys/pal/PLATFORM/mod.rs:LL:CC
12-
= note: inside `std::sys::pal::PLATFORM::fs::File::open_c` at RUSTLIB/std/src/sys/pal/PLATFORM/fs.rs:LL:CC
13-
= note: inside closure at RUSTLIB/std/src/sys/pal/PLATFORM/fs.rs:LL:CC
14-
= note: inside `std::sys::pal::PLATFORM::small_c_string::run_with_cstr_stack::<std::sys::pal::PLATFORM::fs::File>` at RUSTLIB/std/src/sys/pal/PLATFORM/small_c_string.rs:LL:CC
15-
= note: inside `std::sys::pal::PLATFORM::small_c_string::run_with_cstr::<std::sys::pal::PLATFORM::fs::File>` at RUSTLIB/std/src/sys/pal/PLATFORM/small_c_string.rs:LL:CC
16-
= note: inside `std::sys::pal::PLATFORM::small_c_string::run_path_with_cstr::<std::sys::pal::PLATFORM::fs::File>` at RUSTLIB/std/src/sys/pal/PLATFORM/small_c_string.rs:LL:CC
17-
= note: inside `std::sys::pal::PLATFORM::fs::File::open` at RUSTLIB/std/src/sys/pal/PLATFORM/fs.rs:LL:CC
10+
= note: inside closure at RUSTLIB/std/src/sys/fs/PLATFORM.rs:LL:CC
11+
= note: inside `std::sys::pal::PLATFORM::cvt_r::<i32, {closure@std::sys::fs::PLATFORM::File::open_c::{closure#0}}>` at RUSTLIB/std/src/sys/pal/PLATFORM/mod.rs:LL:CC
12+
= note: inside `std::sys::fs::PLATFORM::File::open_c` at RUSTLIB/std/src/sys/fs/PLATFORM.rs:LL:CC
13+
= note: inside closure at RUSTLIB/std/src/sys/fs/PLATFORM.rs:LL:CC
14+
= note: inside `std::sys::pal::PLATFORM::small_c_string::run_with_cstr_stack::<std::sys::fs::PLATFORM::File>` at RUSTLIB/std/src/sys/pal/PLATFORM/small_c_string.rs:LL:CC
15+
= note: inside `std::sys::pal::PLATFORM::small_c_string::run_with_cstr::<std::sys::fs::PLATFORM::File>` at RUSTLIB/std/src/sys/pal/PLATFORM/small_c_string.rs:LL:CC
16+
= note: inside `std::sys::pal::PLATFORM::small_c_string::run_path_with_cstr::<std::sys::fs::PLATFORM::File>` at RUSTLIB/std/src/sys/pal/PLATFORM/small_c_string.rs:LL:CC
17+
= note: inside `std::sys::fs::PLATFORM::File::open` at RUSTLIB/std/src/sys/fs/PLATFORM.rs:LL:CC
1818
= note: inside `std::fs::OpenOptions::_open` at RUSTLIB/std/src/fs.rs:LL:CC
1919
= note: inside `std::fs::OpenOptions::open::<&std::path::Path>` at RUSTLIB/std/src/fs.rs:LL:CC
2020
= note: inside `std::fs::File::open::<&str>` at RUSTLIB/std/src/fs.rs:LL:CC

0 commit comments

Comments
 (0)