Skip to content

Commit

Permalink
Merge pull request managarm#590 from Dennisbonke/sysfs
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennisbonke authored Oct 23, 2023
2 parents ad36dee + f7a4f23 commit cd4d5c2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
21 changes: 15 additions & 6 deletions posix/subsystem/src/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ File::ptSeekAbs(void *object, int64_t offset) {
auto self = static_cast<File *>(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();
}
Expand All @@ -36,8 +39,11 @@ File::ptSeekRel(void *object, int64_t offset) {
auto self = static_cast<File *>(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();
}
Expand All @@ -48,8 +54,11 @@ File::ptSeekEof(void *object, int64_t offset) {
auto self = static_cast<File *>(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();
}
Expand Down
5 changes: 5 additions & 0 deletions posix/subsystem/src/sysfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ void DirectoryFile::handleClose() {
_cancelServe.cancel();
}

// TODO: Verify that this is correct
async::result<frg::expected<Error, off_t>> 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<ReadEntriesResult> DirectoryFile::readEntries() {
if(_iter != _node->_entries.end()) {
Expand Down
1 change: 1 addition & 0 deletions posix/subsystem/src/sysfs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ struct DirectoryFile final : File {

FutureMaybe<ReadEntriesResult> readEntries() override;
helix::BorrowedDescriptor getPassthroughLane() override;
async::result<frg::expected<Error, off_t>> seek(off_t offset, VfsSeek whence) override;

private:
// TODO: Remove this and extract it from the associatedLink().
Expand Down
28 changes: 23 additions & 5 deletions protocols/fs/src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,18 @@ async::detached handlePassthrough(smarter::shared_ptr<void> file,
co_return;
}
auto result = co_await file_ops->seekAbs(file.get(), req.rel_offset());
auto error = std::get_if<Error>(&result);

managarm::fs::SvrResponse resp;
resp.set_error(managarm::fs::Errors::SUCCESS);
resp.set_offset(std::get<int64_t>(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<int64_t>(result));
}

auto ser = resp.SerializeAsString();
auto [send_resp] = co_await helix_ng::exchangeMsgs(
Expand All @@ -68,7 +76,9 @@ async::detached handlePassthrough(smarter::shared_ptr<void> 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<int64_t>(result));
Expand All @@ -94,10 +104,18 @@ async::detached handlePassthrough(smarter::shared_ptr<void> file,
co_return;
}
auto result = co_await file_ops->seekEof(file.get(), req.rel_offset());
auto error = std::get_if<Error>(&result);

managarm::fs::SvrResponse resp;
resp.set_error(managarm::fs::Errors::SUCCESS);
resp.set_offset(std::get<int64_t>(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<int64_t>(result));
}

auto ser = resp.SerializeAsString();
auto [send_resp] = co_await helix_ng::exchangeMsgs(
Expand Down

0 comments on commit cd4d5c2

Please sign in to comment.