Compare commits

..

No commits in common. "d7050ff19f4584ff62610bb4d2de83b4a08b64fd" and "38fb6ca1708ac5eb0f308fcadfb1f79e09aaee9d" have entirely different histories.

18 changed files with 19 additions and 280 deletions

View File

@ -1,8 +1,5 @@
add_library(glacier STATIC add_library(glacier STATIC
string/string.cpp string/string.cpp)
string/string_view.cpp
string/str_split.cpp
)
target_include_directories(glacier target_include_directories(glacier
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}

View File

@ -11,33 +11,10 @@ class Vector {
Vector() : data_(nullptr), size_(0), capacity_(0) {} Vector() : data_(nullptr), size_(0), capacity_(0) {}
Vector(const Vector&) = delete; Vector(const Vector&) = delete;
Vector(Vector&& other) // TODO: Implement Move
: data_(other.data_), size_(other.size_), capacity_(other.capacity_) { Vector(Vector&&) = delete;
other.data_ = nullptr;
other.size_ = 0;
other.capacity_ = 0;
}
Vector& operator=(Vector&& other) {
if (data_) {
delete[] data_;
}
data_ = other.data_; ~Vector() { delete[] data_; }
size_ = other.size_;
capacity_ = other.capacity_;
other.data_ = nullptr;
other.size_ = 0;
other.capacity_ = 0;
return *this;
}
~Vector() {
if (data_) {
delete[] data_;
}
}
// FIXME: Handle downsizing. // FIXME: Handle downsizing.
void Resize(uint64_t capacity); void Resize(uint64_t capacity);

View File

@ -1,17 +0,0 @@
#include "glacier/string/str_split.h"
namespace glcr {
Vector<StringView> StrSplit(const StringView& str, char delimiter) {
Vector<StringView> strings;
uint64_t cur_pos = 0;
uint64_t next_pos = 0;
while ((next_pos = str.find(delimiter, cur_pos)) != str.npos) {
strings.PushBack(str.substr(cur_pos, next_pos - cur_pos));
cur_pos = next_pos + 1;
}
strings.PushBack(str.substr(cur_pos, str.size() - cur_pos));
return strings;
}
} // namespace glcr

View File

@ -1,11 +0,0 @@
#pragma once
#include "glacier/container/vector.h"
#include "glacier/string/string_view.h"
namespace glcr {
// TODO: Add a split that uses a StringView as a delimeter.
Vector<StringView> StrSplit(const StringView& str, char delimeter);
} // namespace glcr

View File

@ -26,8 +26,6 @@ String::String(const char* cstr, uint64_t str_len) : length_(str_len) {
cstr_[length_] = '\0'; cstr_[length_] = '\0';
} }
String::String(StringView str) : String(str.data(), str.size()) {}
bool String::operator==(const String& other) { bool String::operator==(const String& other) {
if (other.length_ != length_) { if (other.length_ != length_) {
return false; return false;
@ -45,6 +43,4 @@ char String::operator[](uint64_t offset) const {
return cstr_[offset]; return cstr_[offset];
} }
String::operator StringView() const { return StringView(cstr_, length_); }
} // namespace glcr } // namespace glcr

View File

@ -2,8 +2,6 @@
#include <stdint.h> #include <stdint.h>
#include "glacier/string/string_view.h"
namespace glcr { namespace glcr {
class String { class String {
@ -11,7 +9,6 @@ class String {
String(); String();
String(const char* cstr); String(const char* cstr);
String(const char* cstr, uint64_t str_len); String(const char* cstr, uint64_t str_len);
String(StringView str);
const char* cstr() const { return cstr_; } const char* cstr() const { return cstr_; }
uint64_t length() const { return length_; } uint64_t length() const { return length_; }
@ -19,7 +16,6 @@ class String {
bool operator==(const String& str); bool operator==(const String& str);
char operator[](uint64_t offset) const; char operator[](uint64_t offset) const;
operator StringView() const;
private: private:
char* cstr_; char* cstr_;

View File

@ -1,73 +0,0 @@
#include "glacier/string/string_view.h"
namespace glcr {
namespace {
uint64_t cstrlen(const char* ptr) {
uint64_t len = 0;
while (ptr[len] != '\0') {
len++;
}
return len;
}
} // namespace
StringView::StringView() {}
StringView::StringView(const char* str) : value_(str), size_(cstrlen(str)) {}
StringView::StringView(const char* str, uint64_t count)
: value_(str), size_(count) {}
const char* StringView::data() const { return value_; }
uint64_t StringView::size() const { return size_; }
bool StringView::empty() const { return size_ == 0; }
char StringView::at(uint64_t pos) const { return value_[pos]; }
uint64_t StringView::find(char c, uint64_t pos) const {
for (uint64_t i = pos; i < size_; i++) {
if (value_[i] == c) {
return i;
}
}
return npos;
}
StringView StringView::substr(uint64_t start, uint64_t count) const {
// FIXME: Report an error here maybe.
if (start >= size_) {
return StringView{};
}
if (start + count > size_) {
count = size_ - start;
}
return StringView(value_ + start, count);
}
bool operator==(const StringView& str1, const StringView& str2) {
if (str1.empty() && str2.empty()) {
return true;
}
if (str1.size() != str2.size()) {
return false;
}
if (str1.data() == str2.data()) {
// Short circuit if they are the same exact string.
return true;
}
for (uint64_t i = 0; i < str1.size(); i++) {
if (str1.at(i) != str2.at(i)) {
return false;
}
}
return true;
}
bool operator!=(const StringView& str1, const StringView& str2) {
return !(str1 == str2);
}
} // namespace glcr

View File

@ -1,35 +0,0 @@
#pragma once
#include <stdint.h>
namespace glcr {
class StringView {
public:
static const uint64_t npos = -1;
StringView();
StringView(const StringView& other) = default;
StringView(const char* str);
StringView(const char* str, uint64_t count);
const char* data() const;
uint64_t size() const;
bool empty() const;
char at(uint64_t pos) const;
uint64_t find(char c, uint64_t pos = 0) const;
StringView substr(uint64_t start, uint64_t count) const;
private:
const char* value_ = nullptr;
uint64_t size_ = 0;
};
bool operator==(const StringView& str1, const StringView& str2);
bool operator!=(const StringView& str1, const StringView& str2);
} // namespace glcr

View File

@ -44,11 +44,9 @@ glcr::ErrorOr<Inode*> Ext2Driver::GetInode(uint32_t inode_number) {
return inode_table_->GetInode(inode_number); return inode_table_->GetInode(inode_number);
} }
glcr::ErrorOr<glcr::Vector<DirEntry>> Ext2Driver::ReadDirectory( glcr::ErrorCode Ext2Driver::ProbeDirectory(Inode* inode) {
uint32_t inode_number) {
ASSIGN_OR_RETURN(Inode * inode, inode_table_->GetInode(inode_number));
if (!(inode->mode & 0x4000)) { if (!(inode->mode & 0x4000)) {
dbgln("Reading non directory."); dbgln("Probing non-directory");
return glcr::INVALID_ARGUMENT; return glcr::INVALID_ARGUMENT;
} }
@ -61,7 +59,6 @@ glcr::ErrorOr<glcr::Vector<DirEntry>> Ext2Driver::ReadDirectory(
return glcr::FAILED_PRECONDITION; return glcr::FAILED_PRECONDITION;
} }
glcr::Vector<DirEntry> directory;
for (uint64_t i = 0; i < real_block_cnt; i++) { for (uint64_t i = 0; i < real_block_cnt; i++) {
dbgln("Getting block %lx", inode->block[i]); dbgln("Getting block %lx", inode->block[i]);
ASSIGN_OR_RETURN(MappedMemoryRegion block, ASSIGN_OR_RETURN(MappedMemoryRegion block,
@ -69,7 +66,6 @@ glcr::ErrorOr<glcr::Vector<DirEntry>> Ext2Driver::ReadDirectory(
uint64_t addr = block.vaddr(); uint64_t addr = block.vaddr();
while (addr < block.vaddr() + ext2_reader_->BlockSize()) { while (addr < block.vaddr() + ext2_reader_->BlockSize()) {
DirEntry* entry = reinterpret_cast<DirEntry*>(addr); DirEntry* entry = reinterpret_cast<DirEntry*>(addr);
directory.PushBack(*entry);
glcr::String name(entry->name, entry->name_len); glcr::String name(entry->name, entry->name_len);
switch (entry->file_type) { switch (entry->file_type) {
case kExt2FtFile: case kExt2FtFile:
@ -84,25 +80,5 @@ glcr::ErrorOr<glcr::Vector<DirEntry>> Ext2Driver::ReadDirectory(
addr += entry->record_length; addr += entry->record_length;
} }
} }
return directory; return glcr::OK;
}
glcr::ErrorOr<MappedMemoryRegion> Ext2Driver::ReadFile(uint64_t inode_number) {
ASSIGN_OR_RETURN(Inode * inode, inode_table_->GetInode(inode_number));
if (!(inode->mode & 0x8000)) {
dbgln("Reading non file.");
return glcr::INVALID_ARGUMENT;
}
// This calculation is cursed.
uint64_t real_block_cnt =
(inode->blocks - 1) / (ext2_reader_->BlockSize() / 512) + 1;
if (real_block_cnt > 1) {
dbgln("Can't handle scatter-gather yet.");
return glcr::UNIMPLEMENTED;
}
return ext2_reader_->ReadBlock(inode->block[0]);
} }

View File

@ -15,10 +15,7 @@ class Ext2Driver {
glcr::ErrorCode ProbePartition(); glcr::ErrorCode ProbePartition();
glcr::ErrorOr<Inode*> GetInode(uint32_t inode_number); glcr::ErrorOr<Inode*> GetInode(uint32_t inode_number);
glcr::ErrorCode ProbeDirectory(Inode* inode);
glcr::ErrorOr<glcr::Vector<DirEntry>> ReadDirectory(uint32_t inode_number);
glcr::ErrorOr<MappedMemoryRegion> ReadFile(uint64_t inode_number);
private: private:
glcr::SharedPtr<Ext2BlockReader> ext2_reader_; glcr::SharedPtr<Ext2BlockReader> ext2_reader_;

View File

@ -20,7 +20,9 @@ uint64_t main(uint64_t init_cap) {
denali_info.device_id(), denali_info.lba_offset()); denali_info.device_id(), denali_info.lba_offset());
ASSIGN_OR_RETURN(Ext2Driver ext2, Ext2Driver::Init(glcr::Move(denali))); ASSIGN_OR_RETURN(Ext2Driver ext2, Ext2Driver::Init(glcr::Move(denali)));
ASSIGN_OR_RETURN(auto server, VFSServer::Create(ext2)); ASSIGN_OR_RETURN(Inode * root, ext2.GetInode(2));
ASSIGN_OR_RETURN(auto server, VFSServer::Create());
Thread server_thread = server->RunServer(); Thread server_thread = server->RunServer();
@ -29,6 +31,7 @@ uint64_t main(uint64_t init_cap) {
ASSIGN_OR_RETURN(auto client, server->CreateClient()); ASSIGN_OR_RETURN(auto client, server->CreateClient());
req.set_endpoint_capability(client.Capability()); req.set_endpoint_capability(client.Capability());
check(yellowstone.RegisterEndpoint(req, empty)); check(yellowstone.RegisterEndpoint(req, empty));
check(ext2.ProbeDirectory(root));
RET_ERR(server_thread.Join()); RET_ERR(server_thread.Join());

View File

@ -1,50 +1,14 @@
#include "victoriafalls_server.h" #include "victoriafalls_server.h"
#include <glacier/string/str_split.h>
#include <mammoth/debug.h>
#include <zcall.h> #include <zcall.h>
glcr::ErrorOr<glcr::UniquePtr<VFSServer>> VFSServer::Create( glcr::ErrorOr<glcr::UniquePtr<VFSServer>> VFSServer::Create() {
Ext2Driver& driver) {
z_cap_t endpoint_cap; z_cap_t endpoint_cap;
RET_ERR(ZEndpointCreate(&endpoint_cap)); RET_ERR(ZEndpointCreate(&endpoint_cap));
return glcr::UniquePtr<VFSServer>(new VFSServer(endpoint_cap, driver)); return glcr::UniquePtr<VFSServer>(new VFSServer(endpoint_cap));
} }
glcr::ErrorCode VFSServer::HandleOpenFile(const OpenFileRequest& request, glcr::ErrorCode VFSServer::HandleOpenFile(const OpenFileRequest&,
OpenFileResponse& response) { OpenFileResponse&) {
auto path_tokens = glcr::StrSplit(request.path(), '/'); return glcr::UNIMPLEMENTED;
// Require all paths to be absolute rather than relative.
// If the path starts with '/' then the first token will be empty.
if (path_tokens.at(0) != "") {
return glcr::INVALID_ARGUMENT;
}
ASSIGN_OR_RETURN(auto files, driver_.ReadDirectory(2));
for (uint64_t i = 1; i < path_tokens.size() - 1; i++) {
for (uint64_t j = 0; j < files.size(); j++) {
if (path_tokens.at(i) ==
glcr::StringView(files.at(j).name, files.at(j).name_len)) {
ASSIGN_OR_RETURN(files, driver_.ReadDirectory(files.at(j).inode));
}
}
dbgln("Directory '%s' not found.", glcr::String(path_tokens.at(i)).cstr());
return glcr::NOT_FOUND;
}
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)) {
ASSIGN_OR_RETURN(region, driver_.ReadFile(files.at(j).inode));
}
}
if (!region) {
dbgln("File '%s' not found.",
glcr::String(path_tokens.at(path_tokens.size() - 1)).cstr());
}
response.set_path(request.path());
response.set_memory(region.cap());
return glcr::OK;
} }

View File

@ -2,20 +2,15 @@
#include <glacier/memory/unique_ptr.h> #include <glacier/memory/unique_ptr.h>
#include "fs/ext2/ext2_driver.h"
#include "victoriafalls/victoriafalls.yunq.server.h" #include "victoriafalls/victoriafalls.yunq.server.h"
class VFSServer : public VFSServerBase { class VFSServer : public VFSServerBase {
public: public:
static glcr::ErrorOr<glcr::UniquePtr<VFSServer>> Create(Ext2Driver& driver); static glcr::ErrorOr<glcr::UniquePtr<VFSServer>> Create();
glcr::ErrorCode HandleOpenFile(const OpenFileRequest&, glcr::ErrorCode HandleOpenFile(const OpenFileRequest&,
OpenFileResponse&) override; OpenFileResponse&) override;
private: private:
// FIXME: Don't store this as a reference. VFSServer(z_cap_t endpoint_cap) : VFSServerBase(endpoint_cap) {}
Ext2Driver& driver_;
VFSServer(z_cap_t endpoint_cap, Ext2Driver& driver)
: VFSServerBase(endpoint_cap), driver_(driver) {}
}; };

View File

@ -12,7 +12,6 @@ target_link_libraries(yellowstone
denali_yunq denali_yunq
mammoth mammoth
glacier glacier
victoriafalls_yunq
yellowstone_yunq yellowstone_yunq
) )

View File

@ -1,7 +1,6 @@
#include <mammoth/debug.h> #include <mammoth/debug.h>
#include <mammoth/endpoint_client.h> #include <mammoth/endpoint_client.h>
#include <mammoth/init.h> #include <mammoth/init.h>
#include <mammoth/memory_region.h>
#include <mammoth/process.h> #include <mammoth/process.h>
#include <zcall.h> #include <zcall.h>
@ -34,18 +33,6 @@ uint64_t main(uint64_t port_cap) {
dbgln("VFS Available."); dbgln("VFS Available.");
auto vfs_client = server->GetVFSClient();
OpenFileRequest request;
request.set_path("/init.txt");
OpenFileResponse response;
check(vfs_client->OpenFile(request, response));
MappedMemoryRegion file =
MappedMemoryRegion::FromCapability(response.memory());
dbgln("addr: %lu, size: %lu", file.vaddr(), file.size());
dbgln("Test: '%s'", file.vaddr());
check(server_thread.Join()); check(server_thread.Join());
dbgln("Yellowstone Finished Successfully."); dbgln("Yellowstone Finished Successfully.");
return 0; return 0;

View File

@ -85,9 +85,6 @@ glcr::ErrorCode YellowstoneServer::HandleRegisterEndpoint(
check(has_denali_mutex_.Release()); check(has_denali_mutex_.Release());
} else if (req.endpoint_name() == "victoriafalls") { } else if (req.endpoint_name() == "victoriafalls") {
victoria_falls_cap_ = req.endpoint_capability(); victoria_falls_cap_ = req.endpoint_capability();
// FIXME: Probably make a separate copy for use within yellowstone vs
// transmit to other processes.
vfs_client_ = glcr::MakeShared<VFSClient>(victoria_falls_cap_);
check(has_victoriafalls_mutex_.Release()); check(has_victoriafalls_mutex_.Release());
} else { } else {
dbgln("[WARN] Got endpoint cap type: %s", req.endpoint_name().cstr()); dbgln("[WARN] Got endpoint cap type: %s", req.endpoint_name().cstr());
@ -104,7 +101,3 @@ glcr::ErrorCode YellowstoneServer::WaitVictoriaFallsRegistered() {
RET_ERR(has_victoriafalls_mutex_.Lock()); RET_ERR(has_victoriafalls_mutex_.Lock());
return has_victoriafalls_mutex_.Release(); return has_victoriafalls_mutex_.Release();
} }
glcr::SharedPtr<VFSClient> YellowstoneServer::GetVFSClient() {
return vfs_client_;
}

View File

@ -1,13 +1,11 @@
#pragma once #pragma once
#include <glacier/memory/shared_ptr.h>
#include <glacier/memory/unique_ptr.h> #include <glacier/memory/unique_ptr.h>
#include <glacier/status/error_or.h> #include <glacier/status/error_or.h>
#include <mammoth/endpoint_server.h> #include <mammoth/endpoint_server.h>
#include <mammoth/mutex.h> #include <mammoth/mutex.h>
#include <mammoth/port_server.h> #include <mammoth/port_server.h>
#include <mammoth/thread.h> #include <mammoth/thread.h>
#include <victoriafalls/victoriafalls.yunq.client.h>
#include "hw/pcie.h" #include "hw/pcie.h"
#include "lib/yellowstone/yellowstone.yunq.server.h" #include "lib/yellowstone/yellowstone.yunq.server.h"
@ -24,15 +22,12 @@ class YellowstoneServer : public YellowstoneServerBase {
glcr::ErrorCode WaitDenaliRegistered(); glcr::ErrorCode WaitDenaliRegistered();
glcr::ErrorCode WaitVictoriaFallsRegistered(); glcr::ErrorCode WaitVictoriaFallsRegistered();
glcr::SharedPtr<VFSClient> GetVFSClient();
private: private:
// TODO: Store these in a data structure. // TODO: Store these in a data structure.
z_cap_t denali_cap_ = 0; z_cap_t denali_cap_ = 0;
uint64_t device_id_ = 0; uint64_t device_id_ = 0;
uint64_t lba_offset_ = 0; uint64_t lba_offset_ = 0;
z_cap_t victoria_falls_cap_ = 0; z_cap_t victoria_falls_cap_ = 0;
glcr::SharedPtr<VFSClient> vfs_client_;
PciReader pci_reader_; PciReader pci_reader_;