diff --git a/posix/subsystem/src/file.cpp b/posix/subsystem/src/file.cpp index 2043470ff..8c6d515eb 100644 --- a/posix/subsystem/src/file.cpp +++ b/posix/subsystem/src/file.cpp @@ -24,8 +24,11 @@ File::ptSeekAbs(void *object, int64_t offset) { auto self = static_cast(object); auto result = co_await self->seek(offset, VfsSeek::absolute); if(!result) { - assert(result.error() == Error::seekOnPipe); - co_return protocols::fs::Error::seekOnPipe; + if(result.error() == Error::seekOnPipe) + co_return protocols::fs::Error::seekOnPipe; + else if(result.error() == Error::illegalArguments) + co_return protocols::fs::Error::illegalArguments; + assert(!"Unexpected error!"); }else{ co_return result.value(); } @@ -36,8 +39,11 @@ File::ptSeekRel(void *object, int64_t offset) { auto self = static_cast(object); auto result = co_await self->seek(offset, VfsSeek::relative); if(!result) { - assert(result.error() == Error::seekOnPipe); - co_return protocols::fs::Error::seekOnPipe; + if(result.error() == Error::seekOnPipe) + co_return protocols::fs::Error::seekOnPipe; + else if(result.error() == Error::illegalArguments) + co_return protocols::fs::Error::illegalArguments; + assert(!"Unexpected error!"); }else{ co_return result.value(); } @@ -48,8 +54,11 @@ File::ptSeekEof(void *object, int64_t offset) { auto self = static_cast(object); auto result = co_await self->seek(offset, VfsSeek::eof); if(!result) { - assert(result.error() == Error::seekOnPipe); - co_return protocols::fs::Error::seekOnPipe; + if(result.error() == Error::seekOnPipe) + co_return protocols::fs::Error::seekOnPipe; + else if(result.error() == Error::illegalArguments) + co_return protocols::fs::Error::illegalArguments; + assert(!"Unexpected error!"); }else{ co_return result.value(); } diff --git a/posix/subsystem/src/sysfs.cpp b/posix/subsystem/src/sysfs.cpp index 4ab35652b..2a9ccf9f5 100644 --- a/posix/subsystem/src/sysfs.cpp +++ b/posix/subsystem/src/sysfs.cpp @@ -119,6 +119,11 @@ void DirectoryFile::handleClose() { _cancelServe.cancel(); } +// TODO: Verify that this is correct +async::result> DirectoryFile::seek(off_t, VfsSeek) { + co_return Error::illegalArguments; +} + // TODO: This iteration mechanism only works as long as _iter is not concurrently deleted. async::result DirectoryFile::readEntries() { if(_iter != _node->_entries.end()) { diff --git a/posix/subsystem/src/sysfs.hpp b/posix/subsystem/src/sysfs.hpp index 1186a2c9e..db8025c74 100644 --- a/posix/subsystem/src/sysfs.hpp +++ b/posix/subsystem/src/sysfs.hpp @@ -66,6 +66,7 @@ struct DirectoryFile final : File { FutureMaybe readEntries() override; helix::BorrowedDescriptor getPassthroughLane() override; + async::result> seek(off_t offset, VfsSeek whence) override; private: // TODO: Remove this and extract it from the associatedLink(). diff --git a/protocols/fs/src/server.cpp b/protocols/fs/src/server.cpp index 61fdcc42a..37ee02b55 100644 --- a/protocols/fs/src/server.cpp +++ b/protocols/fs/src/server.cpp @@ -38,10 +38,18 @@ async::detached handlePassthrough(smarter::shared_ptr file, co_return; } auto result = co_await file_ops->seekAbs(file.get(), req.rel_offset()); + auto error = std::get_if(&result); managarm::fs::SvrResponse resp; - resp.set_error(managarm::fs::Errors::SUCCESS); - resp.set_offset(std::get(result)); + if(error && *error == Error::seekOnPipe) { + resp.set_error(managarm::fs::Errors::SEEK_ON_PIPE); + } else if(error && *error == Error::illegalArguments) { + resp.set_error(managarm::fs::Errors::ILLEGAL_ARGUMENT); + } else { + assert(!error); + resp.set_error(managarm::fs::Errors::SUCCESS); + resp.set_offset(std::get(result)); + } auto ser = resp.SerializeAsString(); auto [send_resp] = co_await helix_ng::exchangeMsgs( @@ -68,7 +76,9 @@ async::detached handlePassthrough(smarter::shared_ptr file, managarm::fs::SvrResponse resp; if(error && *error == Error::seekOnPipe) { resp.set_error(managarm::fs::Errors::SEEK_ON_PIPE); - }else{ + } else if(error && *error == Error::illegalArguments) { + resp.set_error(managarm::fs::Errors::ILLEGAL_ARGUMENT); + } else { assert(!error); resp.set_error(managarm::fs::Errors::SUCCESS); resp.set_offset(std::get(result)); @@ -94,10 +104,18 @@ async::detached handlePassthrough(smarter::shared_ptr file, co_return; } auto result = co_await file_ops->seekEof(file.get(), req.rel_offset()); + auto error = std::get_if(&result); managarm::fs::SvrResponse resp; - resp.set_error(managarm::fs::Errors::SUCCESS); - resp.set_offset(std::get(result)); + if(error && *error == Error::seekOnPipe) { + resp.set_error(managarm::fs::Errors::SEEK_ON_PIPE); + } else if(error && *error == Error::illegalArguments) { + resp.set_error(managarm::fs::Errors::ILLEGAL_ARGUMENT); + } else { + assert(!error); + resp.set_error(managarm::fs::Errors::SUCCESS); + resp.set_offset(std::get(result)); + } auto ser = resp.SerializeAsString(); auto [send_resp] = co_await helix_ng::exchangeMsgs(