#include #include #include #include typedef struct { int Start; int Size; char name[256]; } FILE_DESC; int main(int argc, char **argv) { if (argc == 1) { std::cout << "Usage:mkramfs ..." << std::endl; return -1; } FILE_DESC descriptor[256] = {0}; std::ofstream ramfs("ramfs.img", std::ios::binary | std::ios::ate); for (int i = 1; i < argc; i++) { if (!std::filesystem::exists(std::filesystem::path(argv[i]))) { std::cout << "file does not exist! - " << argv[i] << std::endl; continue; } descriptor[i].Start = descriptor[i - 1].Start + descriptor[i - 1].Size; descriptor[i].Size = std::filesystem::file_size(std::filesystem::path(argv[i])); strncpy(descriptor[i].name, std::filesystem::path(argv[i]).filename().c_str(), 255); } ramfs.write(reinterpret_cast(descriptor), sizeof(descriptor)); for (int i = 1; i < argc; i++) { std::ifstream file(argv[i], std::ios::binary); ramfs << file.rdbuf(); file.close(); } ramfs.close(); }