Move makerd to TOML-based manifest

Added the cpptoml library (and license), and moved to using that for
the initrd manifest. It's now possible to specify the `executable`
flag for files, and the kernel correctly only launches new processes
for the initrd files marked `executable`.
This commit is contained in:
Justin C. Miller
2018-09-08 12:54:35 -07:00
parent 3a39d9440a
commit e7a509176d
9 changed files with 3780 additions and 64 deletions

3658
src/include/cpptoml.h Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -83,7 +83,7 @@ kernel_main(popcorn_data *header)
initrd::disk ird(header->initrd);
log::info(logs::boot, "initrd loaded with %d files.", ird.files().count());
for (auto &f : ird.files())
log::info(logs::boot, " %s (%d bytes).", f.name(), f.size());
log::info(logs::boot, " %s%s (%d bytes).", f.executable() ? "*" : "", f.name(), f.size());
/*
pager->dump_pml4(nullptr, 0);
@@ -144,7 +144,7 @@ kernel_main(popcorn_data *header)
scheduler *sched = new (&scheduler::get()) scheduler(devices->get_lapic());
for (auto &f : ird.files()) {
//if (f.executable())
if (f.executable())
sched->create_process(f.name(), f.data(), f.size());
}

View File

@@ -1,7 +1,10 @@
#include "entry.h"
entry::entry(const std::string &in, const std::string &out) :
m_in(in), m_out(out), m_file(in, std::ios_base::binary)
entry::entry(const std::string &in, const std::string &out, bool executable) :
m_in(in),
m_out(out),
m_file(in, std::ios_base::binary),
m_exec(executable)
{
m_file.seekg(0, std::ios_base::end);
m_size = m_file.tellg();

View File

@@ -5,12 +5,13 @@
class entry
{
public:
entry(const std::string &in, const std::string &out);
entry(const std::string &in, const std::string &out, bool executable = false);
inline const std::string & in() const { return m_in; }
inline const std::string & out() const { return m_out; }
inline const std::ifstream & file() const { return m_file; }
inline bool executable() const { return m_exec; }
inline size_t size() const { return m_size; }
inline bool good() const { return m_file.good(); }
@@ -19,5 +20,6 @@ private:
std::string m_out;
std::ifstream m_file;
size_t m_size;
bool m_exec;
};

View File

@@ -3,6 +3,7 @@
#include <iostream>
#include <string>
#include <vector>
#include "cpptoml.h"
#include "initrd/headers.h"
#include "entry.h"
@@ -14,32 +15,37 @@ int main(int argc, char **argv)
}
std::vector<entry> entries;
std::ifstream manifest(argv[1]);
auto manifest = cpptoml::parse_file(argv[1]);
size_t files_size = 0;
size_t names_size = 0;
while (manifest.good()) {
std::string in, out;
auto files = manifest->get_table_array("files");
for (const auto &file : *files) {
auto dest = file->get_as<std::string>("dest");
if (!dest) {
std::cerr << "File has no destination!" << std::endl;
return 1;
}
manifest >> in;
if (in.length() < 1)
continue;
auto source = file->get_as<std::string>("source");
if (!source) {
std::cerr << "File " << *dest << " has no source!" << std::endl;
return 1;
}
manifest >> out;
if (in.front() == '#')
continue;
auto exec = file->get_as<bool>("executable").value_or(false);
entries.emplace_back(in, out);
entries.emplace_back(*source, *dest, exec);
const entry &e = entries.back();
if (!e.good()) {
std::cerr << "Error reading file: " << in << std::endl;
std::cerr << "Error reading file: " << *source << std::endl;
return 1;
}
files_size += e.size();
names_size += out.length() + 1;
names_size += dest->length() + 1;
}
std::fstream out(argv[2],
@@ -78,6 +84,9 @@ int main(int argc, char **argv)
fheader.length = e.size();
fheader.name_offset = name_offset;
if (e.executable())
fheader.flags |= initrd::file_flags::executable;
out.write(
reinterpret_cast<const char *>(&fheader),
sizeof(fheader));