some modify
This commit is contained in:
8
mkramfs/Makefile
Executable file
8
mkramfs/Makefile
Executable file
@@ -0,0 +1,8 @@
|
||||
CC := g++
|
||||
CFLAGS := -std=c++17
|
||||
|
||||
|
||||
mkramfs: main.cpp
|
||||
$(CC) $(CFLAGS) -o mkramfs main.cpp
|
||||
|
||||
clean: $(RM) mkramfs
|
37
mkramfs/main.cpp
Executable file
37
mkramfs/main.cpp
Executable file
@@ -0,0 +1,37 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
typedef struct {
|
||||
int Start;
|
||||
int Size;
|
||||
char name[256];
|
||||
} FILE_DESC;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc == 1) {
|
||||
std::cout << "Usage:mkramfs <file1> <file2> ..." << 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<char *>(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();
|
||||
}
|
Reference in New Issue
Block a user