mirror of
https://github.com/justinian/jsix.git
synced 2025-12-09 16:04:32 -08:00
Change initrd 'executable' bool to type enum.
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
[[files]]
|
||||
dest = "vdso.so"
|
||||
source = "host/libvdso.so"
|
||||
type = "vdso"
|
||||
|
||||
[[files]]
|
||||
dest = "screenfont.psf"
|
||||
@@ -19,9 +20,9 @@ source = "../assets/fonts/tamsyn8x16r.psf"
|
||||
[[files]]
|
||||
dest = "nulldrv1"
|
||||
source = "user/nulldrv"
|
||||
executable = true
|
||||
type = "executable"
|
||||
|
||||
[[files]]
|
||||
dest = "nulldrv2"
|
||||
source = "user/nulldrv"
|
||||
executable = true
|
||||
type = "executable"
|
||||
|
||||
@@ -108,7 +108,11 @@ kernel_main(kernel_args *header)
|
||||
initrd::disk ird(header->initrd, heap);
|
||||
log::info(logs::boot, "initrd loaded with %d files.", ird.files().count());
|
||||
for (auto &f : ird.files())
|
||||
log::info(logs::boot, " %s%s (%d bytes).", f.executable() ? "*" : "", f.name(), f.size());
|
||||
log::info(logs::boot, " %s%s (%d bytes).",
|
||||
f.type() == initrd::file_type::executable ? "*" :
|
||||
f.type() == initrd::file_type::vdso ? "^" : "",
|
||||
f.name(),
|
||||
f.size());
|
||||
|
||||
/*
|
||||
page_manager::get()->dump_pml4(nullptr, 0);
|
||||
@@ -163,7 +167,7 @@ kernel_main(kernel_args *header)
|
||||
sched->create_kernel_task(-1, logger_task);
|
||||
|
||||
for (auto &f : ird.files()) {
|
||||
if (f.executable())
|
||||
if (f.type() == initrd::file_type::executable)
|
||||
sched->load_process(f.name(), f.data(), f.size());
|
||||
}
|
||||
|
||||
|
||||
13
src/libraries/initrd/include/initrd/file_type.h
Normal file
13
src/libraries/initrd/include/initrd/file_type.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
namespace initrd {
|
||||
|
||||
enum class file_type : uint8_t
|
||||
{
|
||||
unknown,
|
||||
executable,
|
||||
vdso
|
||||
};
|
||||
|
||||
} // namespace initrd
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include "kutil/enum_bitfields.h"
|
||||
#include "initrd/file_type.h"
|
||||
|
||||
namespace initrd {
|
||||
|
||||
@@ -18,10 +19,8 @@ struct disk_header
|
||||
uint8_t reserved[3];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
|
||||
enum class file_flags : uint16_t
|
||||
enum class file_flags : uint8_t
|
||||
{
|
||||
executable = 0x01
|
||||
};
|
||||
|
||||
struct file_header
|
||||
@@ -29,10 +28,10 @@ struct file_header
|
||||
uint32_t offset;
|
||||
uint32_t length;
|
||||
uint16_t name_offset;
|
||||
file_type type;
|
||||
file_flags flags;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
} // namepsace initrd
|
||||
|
||||
IS_BITFIELD(initrd::disk_flags);
|
||||
IS_BITFIELD(initrd::file_flags);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include "kutil/vector.h"
|
||||
#include "initrd/file_type.h"
|
||||
|
||||
// File format:
|
||||
// 1x disk_header
|
||||
@@ -33,8 +34,8 @@ public:
|
||||
/// Get a pointer to the file data
|
||||
const void * data() const;
|
||||
|
||||
/// Whether this file is an executable
|
||||
bool executable() const;
|
||||
/// Type of file
|
||||
file_type type() const;
|
||||
|
||||
private:
|
||||
const file_header *m_header;
|
||||
|
||||
@@ -16,11 +16,7 @@ file::file(const file_header *header, const void *start) :
|
||||
const char * file::name() const { return m_name; }
|
||||
const size_t file::size() const { return m_header->length; }
|
||||
const void * file::data() const { return m_data; }
|
||||
|
||||
bool
|
||||
file::executable() const {
|
||||
return bitfield_has(m_header->flags, file_flags::executable);
|
||||
}
|
||||
file_type file::type() const { return m_header->type; }
|
||||
|
||||
|
||||
disk::disk(const void *start, kutil::allocator &alloc) :
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "entry.h"
|
||||
|
||||
entry::entry(const std::string &in, const std::string &out, bool executable) :
|
||||
entry::entry(const std::string &in, const std::string &out, initrd::file_type type) :
|
||||
m_in(in),
|
||||
m_out(out),
|
||||
m_file(in, std::ios_base::binary),
|
||||
m_exec(executable)
|
||||
m_type(type)
|
||||
{
|
||||
m_file.seekg(0, std::ios_base::end);
|
||||
m_size = m_file.tellg();
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include "initrd/headers.h"
|
||||
|
||||
class entry
|
||||
{
|
||||
public:
|
||||
entry(const std::string &in, const std::string &out, bool executable = false);
|
||||
entry(const std::string &in, const std::string &out, initrd::file_type type);
|
||||
|
||||
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 initrd::file_type type() const { return m_type; }
|
||||
inline size_t size() const { return m_size; }
|
||||
inline bool good() const { return m_file.good(); }
|
||||
|
||||
@@ -20,6 +21,6 @@ private:
|
||||
std::string m_out;
|
||||
std::ifstream m_file;
|
||||
size_t m_size;
|
||||
bool m_exec;
|
||||
initrd::file_type m_type;
|
||||
};
|
||||
|
||||
|
||||
@@ -43,9 +43,15 @@ int main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto exec = file->get_as<bool>("executable").value_or(false);
|
||||
auto type_name = file->get_as<std::string>("type").value_or("unknown");
|
||||
initrd::file_type type = initrd::file_type::unknown;
|
||||
if (type_name == "executable") {
|
||||
type = initrd::file_type::executable;
|
||||
} else if (type_name == "vdso") {
|
||||
type = initrd::file_type::vdso;
|
||||
}
|
||||
|
||||
entries.emplace_back(*source, *dest, exec);
|
||||
entries.emplace_back(*source, *dest, type);
|
||||
const entry &e = entries.back();
|
||||
|
||||
if (!e.good()) {
|
||||
@@ -92,9 +98,7 @@ int main(int argc, char **argv)
|
||||
fheader.offset = file_offset;
|
||||
fheader.length = e.size();
|
||||
fheader.name_offset = name_offset;
|
||||
|
||||
if (e.executable())
|
||||
fheader.flags |= initrd::file_flags::executable;
|
||||
fheader.type = e.type();
|
||||
|
||||
out.write(
|
||||
reinterpret_cast<const char *>(&fheader),
|
||||
|
||||
Reference in New Issue
Block a user