[VictoriaFalls] Add the file size to VFS.OpenFile

This commit is contained in:
Drew Galbraith 2023-11-02 21:02:56 -07:00
parent d7050ff19f
commit bcd9cf09bc
5 changed files with 28 additions and 8 deletions

View File

@ -8,5 +8,6 @@ message OpenFileRequest {
message OpenFileResponse { message OpenFileResponse {
string path; string path;
u64 size;
capability memory; capability memory;
} }

View File

@ -91,6 +91,8 @@ void OpenFileResponse::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t of
auto path_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 0)); auto path_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 0));
set_path(bytes.StringAt(offset + path_pointer.offset, path_pointer.length)); set_path(bytes.StringAt(offset + path_pointer.offset, path_pointer.length));
// Parse size.
set_size(bytes.At<uint64_t>(offset + header_size + (8 * 1)));
// Parse memory. // Parse memory.
// FIXME: Implement in-buffer capabilities for inprocess serialization. // FIXME: Implement in-buffer capabilities for inprocess serialization.
set_memory(0); set_memory(0);
@ -102,14 +104,16 @@ void OpenFileResponse::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t of
auto path_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 0)); auto path_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 0));
set_path(bytes.StringAt(offset + path_pointer.offset, path_pointer.length)); set_path(bytes.StringAt(offset + path_pointer.offset, path_pointer.length));
// Parse size.
set_size(bytes.At<uint64_t>(offset + header_size + (8 * 1)));
// Parse memory. // Parse memory.
uint64_t memory_ptr = bytes.At<uint64_t>(offset + header_size + (8 * 1)); uint64_t memory_ptr = bytes.At<uint64_t>(offset + header_size + (8 * 2));
set_memory(caps.At(memory_ptr)); set_memory(caps.At(memory_ptr));
} }
uint64_t OpenFileResponse::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const { uint64_t OpenFileResponse::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
uint32_t next_extension = header_size + 8 * 2; uint32_t next_extension = header_size + 8 * 3;
const uint32_t core_size = next_extension; const uint32_t core_size = next_extension;
// Write path. // Write path.
ExtPointer path_ptr{ ExtPointer path_ptr{
@ -122,9 +126,11 @@ uint64_t OpenFileResponse::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t of
next_extension += path_ptr.length; next_extension += path_ptr.length;
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), path_ptr); bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), path_ptr);
// Write size.
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), size());
// Write memory. // Write memory.
// FIXME: Implement inbuffer capabilities. // FIXME: Implement inbuffer capabilities.
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), 0); bytes.WriteAt<uint64_t>(offset + header_size + (8 * 2), 0);
// The next extension pointer is the length of the message. // The next extension pointer is the length of the message.
WriteHeader(bytes, offset, core_size, next_extension); WriteHeader(bytes, offset, core_size, next_extension);
@ -133,7 +139,7 @@ uint64_t OpenFileResponse::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t of
} }
uint64_t OpenFileResponse::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const { uint64_t OpenFileResponse::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const {
uint32_t next_extension = header_size + 8 * 2; uint32_t next_extension = header_size + 8 * 3;
const uint32_t core_size = next_extension; const uint32_t core_size = next_extension;
uint64_t next_cap = 0; uint64_t next_cap = 0;
// Write path. // Write path.
@ -147,9 +153,11 @@ uint64_t OpenFileResponse::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t of
next_extension += path_ptr.length; next_extension += path_ptr.length;
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), path_ptr); bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), path_ptr);
// Write size.
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), size());
// Write memory. // Write memory.
caps.WriteAt(next_cap, memory()); caps.WriteAt(next_cap, memory());
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), next_cap++); bytes.WriteAt<uint64_t>(offset + header_size + (8 * 2), next_cap++);
// The next extension pointer is the length of the message. // The next extension pointer is the length of the message.
WriteHeader(bytes, offset, core_size, next_extension); WriteHeader(bytes, offset, core_size, next_extension);

View File

@ -36,11 +36,14 @@ class OpenFileResponse {
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const; uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
glcr::String path() const { return path_; } glcr::String path() const { return path_; }
void set_path(const glcr::String& value) { path_ = value; } void set_path(const glcr::String& value) { path_ = value; }
uint64_t size() const { return size_; }
void set_size(const uint64_t& value) { size_ = value; }
z_cap_t memory() const { return memory_; } z_cap_t memory() const { return memory_; }
void set_memory(const z_cap_t& value) { memory_ = value; } void set_memory(const z_cap_t& value) { memory_ = value; }
private: private:
glcr::String path_; glcr::String path_;
uint64_t size_;
z_cap_t memory_; z_cap_t memory_;
}; };

View File

@ -32,11 +32,14 @@ glcr::ErrorCode VFSServer::HandleOpenFile(const OpenFileRequest& request,
return glcr::NOT_FOUND; return glcr::NOT_FOUND;
} }
uint64_t inode_num;
MappedMemoryRegion region; MappedMemoryRegion region;
for (uint64_t j = 0; j < files.size(); j++) { for (uint64_t j = 0; j < files.size(); j++) {
if (path_tokens.at(path_tokens.size() - 1) == if (path_tokens.at(path_tokens.size() - 1) ==
glcr::StringView(files.at(j).name, files.at(j).name_len)) { glcr::StringView(files.at(j).name, files.at(j).name_len)) {
inode_num = files.at(j).inode;
ASSIGN_OR_RETURN(region, driver_.ReadFile(files.at(j).inode)); ASSIGN_OR_RETURN(region, driver_.ReadFile(files.at(j).inode));
break;
} }
} }
if (!region) { if (!region) {
@ -46,5 +49,9 @@ glcr::ErrorCode VFSServer::HandleOpenFile(const OpenFileRequest& request,
response.set_path(request.path()); response.set_path(request.path());
response.set_memory(region.cap()); response.set_memory(region.cap());
// TODO: Consider folding this up into the actual read call.
ASSIGN_OR_RETURN(Inode * inode, driver_.GetInode(inode_num));
// FIXME: This technically only sets the lower 32 bits.
response.set_size(inode->size);
return glcr::OK; return glcr::OK;
} }

View File

@ -40,11 +40,12 @@ uint64_t main(uint64_t port_cap) {
OpenFileResponse response; OpenFileResponse response;
check(vfs_client->OpenFile(request, response)); check(vfs_client->OpenFile(request, response));
MappedMemoryRegion file = MappedMemoryRegion filemem =
MappedMemoryRegion::FromCapability(response.memory()); MappedMemoryRegion::FromCapability(response.memory());
glcr::String file(reinterpret_cast<const char*>(filemem.vaddr()),
response.size());
dbgln("addr: %lu, size: %lu", file.vaddr(), file.size()); dbgln("Test: '%s'", file.cstr());
dbgln("Test: '%s'", file.vaddr());
check(server_thread.Join()); check(server_thread.Join());
dbgln("Yellowstone Finished Successfully."); dbgln("Yellowstone Finished Successfully.");