mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-26 14:57:38 +00:00
e72c6685ed
Most Chinese devices (and supposedly Galaxy S10) running Android Pie is using system-as-root without A/B partition. https://source.android.com/devices/bootloader/system-as-root#about-system-as-root According to the docs above, these devices will have a ramdisk block with size 0 in their boot images. Since magiskinit can run independently on system-as-root devices, we simply just create an empty ramdisk with magiskinit added as init. Huge thanks to @vvb2060 for the heads up and original PR. Close #980, close #1102
78 lines
1.7 KiB
C++
78 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include <stdint.h>
|
|
#include <string>
|
|
#include <memory>
|
|
#include <map>
|
|
#include <string_view>
|
|
|
|
#include <OutStream.h>
|
|
|
|
struct cpio_newc_header;
|
|
|
|
struct cpio_entry_base {
|
|
uint32_t mode = 0;
|
|
uint32_t uid = 0;
|
|
uint32_t gid = 0;
|
|
uint32_t filesize = 0;
|
|
|
|
void *data = nullptr;
|
|
|
|
cpio_entry_base() : mode(0), uid(0), gid(0), filesize(0) {};
|
|
explicit cpio_entry_base(const cpio_newc_header *h);
|
|
virtual ~cpio_entry_base() = default;
|
|
};
|
|
|
|
struct cpio_entry : public cpio_entry_base {
|
|
std::string filename;
|
|
|
|
cpio_entry() = default;
|
|
explicit cpio_entry(const char *name, uint32_t mode) : filename(name) {
|
|
this->mode = mode;
|
|
}
|
|
explicit cpio_entry(cpio_newc_header *h) : cpio_entry_base(h) {}
|
|
|
|
~cpio_entry() override { free(data); };
|
|
};
|
|
|
|
typedef std::map<std::string_view, std::unique_ptr<cpio_entry_base>> entry_map;
|
|
|
|
class cpio {
|
|
public:
|
|
void dump(const char *file);
|
|
void rm(const char *name, bool r = false);
|
|
void extract();
|
|
bool extract(const char *name, const char *file);
|
|
bool exists(const char *name);
|
|
|
|
protected:
|
|
entry_map entries;
|
|
void rm(entry_map::iterator &it);
|
|
void output(OutStream &out);
|
|
};
|
|
|
|
class cpio_rw : public cpio {
|
|
public:
|
|
cpio_rw() = default;
|
|
explicit cpio_rw(const char *file);
|
|
void load_cpio(const char *file);
|
|
void add(mode_t mode, const char *name, const char *file);
|
|
void mkdir(mode_t mode, const char *name);
|
|
void ln(const char *target, const char *name);
|
|
bool mv(const char *from, const char *to);
|
|
|
|
protected:
|
|
void insert(cpio_entry *e);
|
|
void mv(entry_map::iterator &it, const char *to);
|
|
void load_cpio(char *buf, size_t sz);
|
|
};
|
|
|
|
class cpio_mmap : public cpio {
|
|
public:
|
|
explicit cpio_mmap(const char *file);
|
|
~cpio_mmap();
|
|
private:
|
|
char *buf;
|
|
size_t sz;
|
|
};
|