2022-12-18 15:38:47 +00:00
|
|
|
#pragma once
|
|
|
|
#include <luna/Result.h>
|
|
|
|
#include <luna/Types.h>
|
2023-01-11 17:42:50 +00:00
|
|
|
#include <sys/types.h>
|
2022-12-18 15:38:47 +00:00
|
|
|
|
|
|
|
class TarStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum class EntryType
|
|
|
|
{
|
|
|
|
RegularFile,
|
|
|
|
Directory
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Entry
|
|
|
|
{
|
|
|
|
char name[257];
|
|
|
|
usize size;
|
2023-01-11 17:42:50 +00:00
|
|
|
mode_t mode;
|
2022-12-18 15:38:47 +00:00
|
|
|
EntryType type;
|
|
|
|
|
2023-03-10 23:55:26 +00:00
|
|
|
const u8* data() const
|
|
|
|
{
|
|
|
|
return m_data;
|
|
|
|
}
|
|
|
|
|
2022-12-18 15:38:47 +00:00
|
|
|
private:
|
2023-03-10 23:55:26 +00:00
|
|
|
u8* m_data;
|
2022-12-18 15:38:47 +00:00
|
|
|
|
|
|
|
friend class TarStream;
|
|
|
|
};
|
|
|
|
|
2022-12-23 10:33:23 +00:00
|
|
|
TarStream() = default;
|
2022-12-18 15:38:47 +00:00
|
|
|
TarStream(void* base, usize size);
|
|
|
|
|
|
|
|
void initialize(void* base, usize size);
|
|
|
|
|
2023-01-11 16:30:53 +00:00
|
|
|
Result<bool> read_next_entry(Entry& out);
|
2022-12-18 15:38:47 +00:00
|
|
|
|
|
|
|
void rewind();
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct [[gnu::packed]] TarHeader
|
|
|
|
{
|
|
|
|
char name[100];
|
|
|
|
char mode[8];
|
|
|
|
char uid[8];
|
|
|
|
char gid[8];
|
|
|
|
char size[12];
|
|
|
|
char mtime[12];
|
|
|
|
char chksum[8];
|
|
|
|
char typeflag;
|
|
|
|
char linkname[100];
|
|
|
|
char magic[6];
|
|
|
|
char version[2];
|
|
|
|
char uname[32];
|
|
|
|
char gname[32];
|
|
|
|
char devmajor[8];
|
|
|
|
char devminor[8];
|
|
|
|
char prefix[155];
|
|
|
|
};
|
|
|
|
|
2023-01-11 16:30:53 +00:00
|
|
|
void find_valid_header(TarHeader* out, bool& success);
|
2022-12-18 15:38:47 +00:00
|
|
|
|
2023-01-11 16:30:53 +00:00
|
|
|
void read_header(TarHeader* out, bool& success);
|
2022-12-18 15:38:47 +00:00
|
|
|
Result<Entry> parse_header(const TarHeader* hdr);
|
|
|
|
|
|
|
|
void* m_base;
|
|
|
|
void* m_pos;
|
|
|
|
usize m_size;
|
|
|
|
usize m_offset = 0;
|
2023-01-02 12:07:29 +00:00
|
|
|
};
|