alnyan/yggdrasil: fsync()/truncate()/set_times()
This commit is contained in:
parent
82cfeff7e1
commit
1889f07f89
@ -1,5 +1,5 @@
|
||||
use yggdrasil_rt::io::{
|
||||
FileMetadataUpdate, FileMetadataUpdateMode, FileMode as OsFileMode,
|
||||
FileMetadataUpdate, FileMetadataUpdateMode, FileMode as OsFileMode, FileSync, FileTimesUpdate,
|
||||
OpenOptions as OsOpenOptions, SeekFrom as OsSeekFrom,
|
||||
};
|
||||
|
||||
@ -96,17 +96,17 @@ impl File {
|
||||
}
|
||||
|
||||
pub fn fsync(&self) -> io::Result<()> {
|
||||
crate::debug_trace!("TODO: fsync()");
|
||||
Ok(())
|
||||
unsafe {
|
||||
cvt_io(yggdrasil_rt::sys::fsync(self.as_raw_fd(), FileSync::METADATA | FileSync::DATA))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn datasync(&self) -> io::Result<()> {
|
||||
crate::debug_trace!("TODO: datasync()");
|
||||
Ok(())
|
||||
unsafe { cvt_io(yggdrasil_rt::sys::fsync(self.as_raw_fd(), FileSync::DATA)) }
|
||||
}
|
||||
|
||||
pub fn truncate(&self, _size: u64) -> io::Result<()> {
|
||||
todo!()
|
||||
pub fn truncate(&self, size: u64) -> io::Result<()> {
|
||||
unsafe { cvt_io(yggdrasil_rt::sys::truncate(self.as_raw_fd(), size)) }
|
||||
}
|
||||
|
||||
pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
@ -164,9 +164,18 @@ impl File {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_times(&self, _times: FileTimes) -> io::Result<()> {
|
||||
crate::debug_trace!("TODO: File::set_times()");
|
||||
Ok(())
|
||||
pub fn set_times(&self, times: FileTimes) -> io::Result<()> {
|
||||
cvt_io(unsafe {
|
||||
yggdrasil_rt::sys::update_metadata(
|
||||
Some(self.as_raw_fd()),
|
||||
"",
|
||||
&FileMetadataUpdate::Times(FileTimesUpdate {
|
||||
atime: times.atime,
|
||||
mtime: times.mtime,
|
||||
ctime: None,
|
||||
}),
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use yggdrasil_rt::io::{
|
||||
FileAttr as OsFileAttr, FileMetadataUpdate, FileMetadataUpdateMode, FileMode as OsFileMode,
|
||||
FileType as OsFileType, RawFd as OsRawFd, Rename,
|
||||
AccessMode as OsAccessMode, FileAttr as OsFileAttr, FileMetadataUpdate, FileMetadataUpdateMode,
|
||||
FileMode as OsFileMode, FileType as OsFileType, RawFd as OsRawFd, Rename,
|
||||
};
|
||||
use yggdrasil_rt::time::SystemTime as RtSystemTime;
|
||||
|
||||
@ -9,7 +9,7 @@ use crate::os::yggdrasil::fs::{MetadataExt, OpenOptionsExt};
|
||||
use crate::path::{Path, PathBuf};
|
||||
use crate::sys::time::SystemTime;
|
||||
use crate::sys::{cvt_io, run_with_path_str};
|
||||
use crate::{fmt, io};
|
||||
use crate::{fmt, io, os};
|
||||
|
||||
mod dir;
|
||||
mod file;
|
||||
@ -27,7 +27,10 @@ pub struct FilePermissions(OsFileMode);
|
||||
pub struct FileType(OsFileType);
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default)]
|
||||
pub struct FileTimes {}
|
||||
pub struct FileTimes {
|
||||
atime: Option<RtSystemTime>,
|
||||
mtime: Option<RtSystemTime>,
|
||||
}
|
||||
|
||||
impl FileAttr {
|
||||
pub fn size(&self) -> u64 {
|
||||
@ -117,12 +120,12 @@ impl fmt::Debug for FileType {
|
||||
}
|
||||
|
||||
impl FileTimes {
|
||||
pub fn set_accessed(&mut self, _t: SystemTime) {
|
||||
crate::debug_trace!("TODO: FileTimes::set_accessed()");
|
||||
pub fn set_accessed(&mut self, t: SystemTime) {
|
||||
self.atime = Some(t.0);
|
||||
}
|
||||
|
||||
pub fn set_modified(&mut self, _t: SystemTime) {
|
||||
crate::debug_trace!("TODO: FileTimes::set_modified()");
|
||||
pub fn set_modified(&mut self, t: SystemTime) {
|
||||
self.mtime = Some(t.0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -176,12 +179,12 @@ pub fn readlink(path: &Path) -> io::Result<PathBuf> {
|
||||
Ok(PathBuf::from(path))
|
||||
}
|
||||
|
||||
pub fn symlink(_original: &Path, _link: &Path) -> io::Result<()> {
|
||||
todo!()
|
||||
pub fn symlink(original: &Path, link: &Path) -> io::Result<()> {
|
||||
os::yggdrasil::fs::symlink(original, link)
|
||||
}
|
||||
|
||||
pub fn link(_original: &Path, _link: &Path) -> io::Result<()> {
|
||||
todo!()
|
||||
Err(io::Error::new(io::ErrorKind::Uncategorized, "Hard links are not implemented"))
|
||||
}
|
||||
|
||||
pub fn stat(path: &Path) -> io::Result<FileAttr> {
|
||||
@ -210,10 +213,9 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
|
||||
crate::io::copy(&mut src, &mut dst)
|
||||
}
|
||||
|
||||
pub fn try_exists(_path: &Path) -> io::Result<bool> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn exists(path: &Path) -> io::Result<bool> {
|
||||
try_exists(path)
|
||||
run_with_path_str(path, |path| {
|
||||
cvt_io(unsafe { yggdrasil_rt::sys::check_access(None, path, OsAccessMode::empty()) })
|
||||
})
|
||||
.map(|_| true)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user