alnyan/yggdrasil: fsync()/truncate()/set_times()
This commit is contained in:
parent
82cfeff7e1
commit
1889f07f89
@ -1,5 +1,5 @@
|
|||||||
use yggdrasil_rt::io::{
|
use yggdrasil_rt::io::{
|
||||||
FileMetadataUpdate, FileMetadataUpdateMode, FileMode as OsFileMode,
|
FileMetadataUpdate, FileMetadataUpdateMode, FileMode as OsFileMode, FileSync, FileTimesUpdate,
|
||||||
OpenOptions as OsOpenOptions, SeekFrom as OsSeekFrom,
|
OpenOptions as OsOpenOptions, SeekFrom as OsSeekFrom,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -96,17 +96,17 @@ impl File {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn fsync(&self) -> io::Result<()> {
|
pub fn fsync(&self) -> io::Result<()> {
|
||||||
crate::debug_trace!("TODO: fsync()");
|
unsafe {
|
||||||
Ok(())
|
cvt_io(yggdrasil_rt::sys::fsync(self.as_raw_fd(), FileSync::METADATA | FileSync::DATA))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn datasync(&self) -> io::Result<()> {
|
pub fn datasync(&self) -> io::Result<()> {
|
||||||
crate::debug_trace!("TODO: datasync()");
|
unsafe { cvt_io(yggdrasil_rt::sys::fsync(self.as_raw_fd(), FileSync::DATA)) }
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn truncate(&self, _size: u64) -> io::Result<()> {
|
pub fn truncate(&self, size: u64) -> io::Result<()> {
|
||||||
todo!()
|
unsafe { cvt_io(yggdrasil_rt::sys::truncate(self.as_raw_fd(), size)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
|
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<()> {
|
pub fn set_times(&self, times: FileTimes) -> io::Result<()> {
|
||||||
crate::debug_trace!("TODO: File::set_times()");
|
cvt_io(unsafe {
|
||||||
Ok(())
|
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::{
|
use yggdrasil_rt::io::{
|
||||||
FileAttr as OsFileAttr, FileMetadataUpdate, FileMetadataUpdateMode, FileMode as OsFileMode,
|
AccessMode as OsAccessMode, FileAttr as OsFileAttr, FileMetadataUpdate, FileMetadataUpdateMode,
|
||||||
FileType as OsFileType, RawFd as OsRawFd, Rename,
|
FileMode as OsFileMode, FileType as OsFileType, RawFd as OsRawFd, Rename,
|
||||||
};
|
};
|
||||||
use yggdrasil_rt::time::SystemTime as RtSystemTime;
|
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::path::{Path, PathBuf};
|
||||||
use crate::sys::time::SystemTime;
|
use crate::sys::time::SystemTime;
|
||||||
use crate::sys::{cvt_io, run_with_path_str};
|
use crate::sys::{cvt_io, run_with_path_str};
|
||||||
use crate::{fmt, io};
|
use crate::{fmt, io, os};
|
||||||
|
|
||||||
mod dir;
|
mod dir;
|
||||||
mod file;
|
mod file;
|
||||||
@ -27,7 +27,10 @@ pub struct FilePermissions(OsFileMode);
|
|||||||
pub struct FileType(OsFileType);
|
pub struct FileType(OsFileType);
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Default)]
|
#[derive(Copy, Clone, Debug, Default)]
|
||||||
pub struct FileTimes {}
|
pub struct FileTimes {
|
||||||
|
atime: Option<RtSystemTime>,
|
||||||
|
mtime: Option<RtSystemTime>,
|
||||||
|
}
|
||||||
|
|
||||||
impl FileAttr {
|
impl FileAttr {
|
||||||
pub fn size(&self) -> u64 {
|
pub fn size(&self) -> u64 {
|
||||||
@ -117,12 +120,12 @@ impl fmt::Debug for FileType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FileTimes {
|
impl FileTimes {
|
||||||
pub fn set_accessed(&mut self, _t: SystemTime) {
|
pub fn set_accessed(&mut self, t: SystemTime) {
|
||||||
crate::debug_trace!("TODO: FileTimes::set_accessed()");
|
self.atime = Some(t.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_modified(&mut self, _t: SystemTime) {
|
pub fn set_modified(&mut self, t: SystemTime) {
|
||||||
crate::debug_trace!("TODO: FileTimes::set_modified()");
|
self.mtime = Some(t.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,12 +179,12 @@ pub fn readlink(path: &Path) -> io::Result<PathBuf> {
|
|||||||
Ok(PathBuf::from(path))
|
Ok(PathBuf::from(path))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn symlink(_original: &Path, _link: &Path) -> io::Result<()> {
|
pub fn symlink(original: &Path, link: &Path) -> io::Result<()> {
|
||||||
todo!()
|
os::yggdrasil::fs::symlink(original, link)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn link(_original: &Path, _link: &Path) -> io::Result<()> {
|
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> {
|
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)
|
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> {
|
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