[VictoriaFalls] Add the file size to VFS.OpenFile
This commit is contained in:
parent
d7050ff19f
commit
bcd9cf09bc
|
@ -8,5 +8,6 @@ message OpenFileRequest {
|
|||
|
||||
message OpenFileResponse {
|
||||
string path;
|
||||
u64 size;
|
||||
capability memory;
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
||||
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.
|
||||
// FIXME: Implement in-buffer capabilities for inprocess serialization.
|
||||
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));
|
||||
|
||||
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.
|
||||
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));
|
||||
}
|
||||
|
||||
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;
|
||||
// Write path.
|
||||
ExtPointer path_ptr{
|
||||
|
@ -122,9 +126,11 @@ uint64_t OpenFileResponse::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t of
|
|||
next_extension += path_ptr.length;
|
||||
|
||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), path_ptr);
|
||||
// Write size.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), size());
|
||||
// Write memory.
|
||||
// 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.
|
||||
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 {
|
||||
uint32_t next_extension = header_size + 8 * 2;
|
||||
uint32_t next_extension = header_size + 8 * 3;
|
||||
const uint32_t core_size = next_extension;
|
||||
uint64_t next_cap = 0;
|
||||
// Write path.
|
||||
|
@ -147,9 +153,11 @@ uint64_t OpenFileResponse::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t of
|
|||
next_extension += path_ptr.length;
|
||||
|
||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), path_ptr);
|
||||
// Write size.
|
||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), size());
|
||||
// Write 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.
|
||||
WriteHeader(bytes, offset, core_size, next_extension);
|
||||
|
|
|
@ -36,11 +36,14 @@ class OpenFileResponse {
|
|||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
||||
glcr::String path() const { return path_; }
|
||||
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_; }
|
||||
void set_memory(const z_cap_t& value) { memory_ = value; }
|
||||
|
||||
private:
|
||||
glcr::String path_;
|
||||
uint64_t size_;
|
||||
z_cap_t memory_;
|
||||
|
||||
};
|
|
@ -32,11 +32,14 @@ glcr::ErrorCode VFSServer::HandleOpenFile(const OpenFileRequest& request,
|
|||
return glcr::NOT_FOUND;
|
||||
}
|
||||
|
||||
uint64_t inode_num;
|
||||
MappedMemoryRegion region;
|
||||
for (uint64_t j = 0; j < files.size(); j++) {
|
||||
if (path_tokens.at(path_tokens.size() - 1) ==
|
||||
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));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!region) {
|
||||
|
@ -46,5 +49,9 @@ glcr::ErrorCode VFSServer::HandleOpenFile(const OpenFileRequest& request,
|
|||
|
||||
response.set_path(request.path());
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -40,11 +40,12 @@ uint64_t main(uint64_t port_cap) {
|
|||
OpenFileResponse response;
|
||||
check(vfs_client->OpenFile(request, response));
|
||||
|
||||
MappedMemoryRegion file =
|
||||
MappedMemoryRegion filemem =
|
||||
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.vaddr());
|
||||
dbgln("Test: '%s'", file.cstr());
|
||||
|
||||
check(server_thread.Join());
|
||||
dbgln("Yellowstone Finished Successfully.");
|
||||
|
|
Loading…
Reference in New Issue