Unseekable files need not to manipulate the offset

This commit is contained in:
Shaowei Song
2024-09-02 09:48:15 +00:00
committed by Tate, Hongliang Tian
parent 92680ea25d
commit 9638744712
3 changed files with 19 additions and 0 deletions

View File

@ -48,6 +48,10 @@ impl InodeHandle_ {
return file_io.read(writer);
}
if !self.dentry.inode().is_seekable() {
return self.read_at(0, writer);
}
let mut offset = self.offset.lock();
let len = self.read_at(*offset, writer)?;
@ -61,6 +65,10 @@ impl InodeHandle_ {
return file_io.write(reader);
}
if !self.dentry.inode().is_seekable() {
return self.write_at(0, reader);
}
let mut offset = self.offset.lock();
if self.status_flags().contains(StatusFlags::O_APPEND) {

View File

@ -1189,6 +1189,13 @@ impl Inode for RamInode {
return_errno_with_message!(Errno::EINVAL, "ioctl is not supported");
}
fn is_seekable(&self) -> bool {
!matches!(
self.typ,
InodeType::NamedPipe | InodeType::CharDevice | InodeType::Dir | InodeType::Socket
)
}
fn extension(&self) -> Option<&Extension> {
Some(&self.extension)
}

View File

@ -426,6 +426,10 @@ pub trait Inode: Any + Sync + Send {
true
}
fn is_seekable(&self) -> bool {
true
}
/// Get the extension of this inode
fn extension(&self) -> Option<&Extension> {
None