mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
[initrd] Remove old initrd library
We no longer use this library or initrd images in general.
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include "kutil/enum_bitfields.h"
|
||||
|
||||
namespace initrd {
|
||||
|
||||
|
||||
enum class disk_flags : uint16_t
|
||||
{
|
||||
};
|
||||
|
||||
struct disk_header
|
||||
{
|
||||
uint16_t file_count;
|
||||
disk_flags flags;
|
||||
uint32_t length;
|
||||
uint8_t checksum;
|
||||
uint8_t reserved[3];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
|
||||
enum class file_flags : uint16_t
|
||||
{
|
||||
executable = 0x01,
|
||||
symbols = 0x02
|
||||
};
|
||||
|
||||
struct file_header
|
||||
{
|
||||
uint32_t offset;
|
||||
uint32_t length;
|
||||
uint16_t name_offset;
|
||||
file_flags flags;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
} // namepsace initrd
|
||||
|
||||
IS_BITFIELD(initrd::disk_flags);
|
||||
IS_BITFIELD(initrd::file_flags);
|
||||
@@ -1,64 +0,0 @@
|
||||
#pragma once
|
||||
/// \file initrd.h
|
||||
/// Definitions defining the simple inital ramdisk file format used by the
|
||||
/// jsix kernel.
|
||||
|
||||
#include <stdint.h>
|
||||
#include "kutil/vector.h"
|
||||
|
||||
// File format:
|
||||
// 1x disk_header
|
||||
// Nx file_header
|
||||
// filename string data
|
||||
// file data
|
||||
|
||||
namespace initrd {
|
||||
|
||||
struct disk_header;
|
||||
struct file_header;
|
||||
|
||||
|
||||
/// Encasulates methods for a file on the ramdisk
|
||||
class file
|
||||
{
|
||||
public:
|
||||
file(const file_header *header, const void *start);
|
||||
|
||||
/// Get the filename
|
||||
const char * name() const;
|
||||
|
||||
/// Get the file size
|
||||
const size_t size() const;
|
||||
|
||||
/// Get a pointer to the file data
|
||||
const void * data() const;
|
||||
|
||||
/// Whether this file is an executable
|
||||
bool executable() const;
|
||||
|
||||
/// Whether this file is a symbol table
|
||||
bool symbols() const;
|
||||
|
||||
private:
|
||||
const file_header *m_header;
|
||||
void const *m_data;
|
||||
char const *m_name;
|
||||
};
|
||||
|
||||
|
||||
/// Encasulates access methods for the ramdisk
|
||||
class disk
|
||||
{
|
||||
public:
|
||||
/// Constructor.
|
||||
/// \arg start The start of the initrd in memory
|
||||
disk(const void *start);
|
||||
|
||||
/// Get the vector of files on the disk
|
||||
const kutil::vector<file> & files() const { return m_files; }
|
||||
|
||||
private:
|
||||
kutil::vector<file> m_files;
|
||||
};
|
||||
|
||||
} // namespace initrd
|
||||
@@ -1,46 +0,0 @@
|
||||
#include "initrd/headers.h"
|
||||
#include "initrd/initrd.h"
|
||||
#include "kutil/assert.h"
|
||||
#include "kutil/enum_bitfields.h"
|
||||
|
||||
namespace initrd {
|
||||
|
||||
file::file(const file_header *header, const void *start) :
|
||||
m_header(header)
|
||||
{
|
||||
m_data = kutil::offset_pointer(start, m_header->offset);
|
||||
auto *name = kutil::offset_pointer(start, m_header->name_offset);
|
||||
m_name = reinterpret_cast<const char *>(name);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
bool
|
||||
file::symbols() const {
|
||||
return bitfield_has(m_header->flags, file_flags::symbols);
|
||||
}
|
||||
|
||||
|
||||
disk::disk(const void *start)
|
||||
{
|
||||
auto *header = reinterpret_cast<const disk_header *>(start);
|
||||
size_t length = header->length;
|
||||
uint8_t sum = kutil::checksum(start, length);
|
||||
kassert(sum == 0, "initrd checksum failed");
|
||||
|
||||
auto *files = reinterpret_cast<const file_header *>(header + 1);
|
||||
|
||||
m_files.ensure_capacity(header->file_count);
|
||||
for (int i = 0; i < header->file_count; ++i) {
|
||||
m_files.emplace(&files[i], start);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace initrd
|
||||
Reference in New Issue
Block a user