diff --git a/litebox/src/fs/errors.rs b/litebox/src/fs/errors.rs index 459caaea27..ae5ba04c46 100644 --- a/litebox/src/fs/errors.rs +++ b/litebox/src/fs/errors.rs @@ -79,6 +79,8 @@ pub enum SeekError { InvalidOffset, #[error("non-seekable file")] NonSeekable, + #[error("file descriptor is not open for seeking")] + NotOpenForSeeking, #[error("I/O error")] Io, } @@ -92,6 +94,8 @@ pub enum TruncateError { IsDirectory, #[error("file is not opened for writing")] NotForWriting, + #[error("file descriptor is not open for writing")] + NotOpenForWriting, #[error("file descriptor points to a terminal device")] IsTerminalDevice, #[error("I/O error")] @@ -194,6 +198,8 @@ pub enum ReadDirError { ClosedFd, #[error("fd does not point to a directory")] NotADirectory, + #[error("file descriptor is not open for reading")] + NotOpenForReading, #[error("I/O error")] Io, } diff --git a/litebox/src/fs/resolver.rs b/litebox/src/fs/resolver.rs index 225f440261..6ea5bacd84 100644 --- a/litebox/src/fs/resolver.rs +++ b/litebox/src/fs/resolver.rs @@ -651,6 +651,9 @@ impl 0, @@ -699,6 +698,9 @@ impl 0, @@ -752,8 +750,7 @@ impl return Err(SeekError::NotAFile), }; if entry.entry.path_only { - // TODO(jayb): Add an error variant for operations not permitted on O_PATH fds. - unimplemented!("seek on O_PATH fd") + return Err(SeekError::NotOpenForSeeking); } match entry.entry.seek_behavior { @@ -806,13 +803,12 @@ impl file, Handle::Dir(_) => return Err(TruncateError::IsDirectory), }; + if entry.entry.path_only { + return Err(TruncateError::NotOpenForWriting); + } if !entry.entry.write_allowed { return Err(TruncateError::NotForWriting); } - if entry.entry.path_only { - // TODO(jayb): Add an error variant for operations not permitted on O_PATH fds. - unimplemented!("truncate O_PATH fd") - } self.backend.truncate(file, length)?; if reset_offset { @@ -957,8 +953,7 @@ impl return Err(ReadDirError::NotADirectory), diff --git a/litebox_common_linux/src/errno/mod.rs b/litebox_common_linux/src/errno/mod.rs index c5397ab4c2..6107f83b6e 100644 --- a/litebox_common_linux/src/errno/mod.rs +++ b/litebox_common_linux/src/errno/mod.rs @@ -213,6 +213,7 @@ impl From for Errno { } litebox::fs::errors::SeekError::InvalidOffset => Errno::EINVAL, litebox::fs::errors::SeekError::NonSeekable => Errno::ESPIPE, + litebox::fs::errors::SeekError::NotOpenForSeeking => Errno::EBADF, litebox::fs::errors::SeekError::Io => Errno::EIO, _ => unimplemented!(), } @@ -540,6 +541,7 @@ impl From for Errno { fn from(value: litebox::fs::errors::ReadDirError) -> Self { match value { litebox::fs::errors::ReadDirError::NotADirectory => Errno::ENOTDIR, + litebox::fs::errors::ReadDirError::NotOpenForReading => Errno::EBADF, _ => unimplemented!(), } } @@ -601,6 +603,7 @@ impl From for Errno { match value { litebox::fs::errors::TruncateError::IsDirectory => Errno::EISDIR, litebox::fs::errors::TruncateError::NotForWriting => Errno::EACCES, + litebox::fs::errors::TruncateError::NotOpenForWriting => Errno::EBADF, litebox::fs::errors::TruncateError::IsTerminalDevice => Errno::EINVAL, litebox::fs::errors::TruncateError::ClosedFd => Errno::EBADF, litebox::fs::errors::TruncateError::Io => Errno::EIO,