diff options
author | Alexis211 <alexis211@gmail.com> | 2009-09-13 18:34:39 +0200 |
---|---|---|
committer | Alexis211 <alexis211@gmail.com> | 2009-09-13 18:34:39 +0200 |
commit | 23c20becb3542c7d5fa041ec69902abe8e2c8d64 (patch) | |
tree | fd573796e5f00cf9f61de0a3a392bd790d5d5ac9 /Source/Tools | |
parent | c4f0f07dfcb946bfceb80790aa7e5e3ec0647e04 (diff) | |
parent | 668bbfdaea7e8cba8233ebffe2a9d46a66e257cd (diff) | |
download | Melon-23c20becb3542c7d5fa041ec69902abe8e2c8d64.tar.gz Melon-23c20becb3542c7d5fa041ec69902abe8e2c8d64.zip |
Merge branch 'vfs'
Diffstat (limited to 'Source/Tools')
-rwxr-xr-x | Source/Tools/MakeRamFS/MakeRamFS | bin | 0 -> 12483 bytes | |||
-rw-r--r-- | Source/Tools/MakeRamFS/Makefile | 38 | ||||
-rw-r--r-- | Source/Tools/MakeRamFS/main.cpp | 95 |
3 files changed, 133 insertions, 0 deletions
diff --git a/Source/Tools/MakeRamFS/MakeRamFS b/Source/Tools/MakeRamFS/MakeRamFS Binary files differnew file mode 100755 index 0000000..be1dc1a --- /dev/null +++ b/Source/Tools/MakeRamFS/MakeRamFS diff --git a/Source/Tools/MakeRamFS/Makefile b/Source/Tools/MakeRamFS/Makefile new file mode 100644 index 0000000..019ec29 --- /dev/null +++ b/Source/Tools/MakeRamFS/Makefile @@ -0,0 +1,38 @@ +.PHONY: clean, mrproper + +CC = gcc +CXX = g++ +LD = gcc +LDFLAGS = -lstdc++ +CFLAGS = +CXXFLAGS = + +OutFile = MakeRamFS +Objects = main.o + +all: $(OutFile) + echo "* Done with $(OutFile)." + +rebuild: mrproper all + +$(OutFile): $(Objects) + echo "* Linking executable : $(OutFile)..." + $(LD) -o $(OutFile) $(LDFLAGS) $^ + +%.o: %.c + echo "* Compiling $<..." + $(CC) -c $< -o $@ $(CFLAGS) + +%.o: %.cpp + echo "* Compiling $<..." + $(CXX) -c $< -o $@ $(CXXFLAGS) + +clean: + echo "* Removing object files..." + rm -rf *.o + rm -rf */*.o + rm -rf */*/*.o + +mrproper: clean + echo "* Removing executable : $(OutFile)" + rm -rf $(OutFile) diff --git a/Source/Tools/MakeRamFS/main.cpp b/Source/Tools/MakeRamFS/main.cpp new file mode 100644 index 0000000..dcb2a2b --- /dev/null +++ b/Source/Tools/MakeRamFS/main.cpp @@ -0,0 +1,95 @@ +#include <iostream> +#include <fstream> +#include <string> + +using namespace std; + +struct ramfs_header { + unsigned int magic; //For error checking + unsigned int files; +}; + +struct ramfs_file_header { + unsigned int name_length; + unsigned int file_length; +}; + +#define INITRD_MAGIC 0x1337BEEF + +int main(int argc, char *argv[]) { + if (argc < 2) { + cerr << "Error : no output file specified." << endl; + cerr << "Usage : MakeRamFS <output.img> [<filename>:<ramfs filename> [...] ]" << endl; + return 1; + } + + ofstream output(argv[1], ios::out | ios::binary); + + ramfs_header hdr; + hdr.magic = INITRD_MAGIC; + hdr.files = argc - 2; + + output.write((char*)&hdr, sizeof(ramfs_header)); + + for (int i = 2; i < argc; i++) { + string name(argv[i]); + string file; + while (!name.empty()) { + if (name[0] == ':') { + name = name.substr(1, name.size() - 1); + break; + } + file += name[0]; + name = name.substr(1, name.size() - 1); + } + + ramfs_file_header fhdr; + + if (file == "") { //This is a directory + fhdr.name_length = name.size(); + fhdr.file_length = 0; //File length of 0 means directory + output.write((char*)&fhdr, sizeof(ramfs_file_header)); + output << name; + output << '\0'; + continue; + } + + ifstream infile(file.c_str(), ios::in | ios::binary); + + if (!infile) { + fhdr.name_length = 0; //Name and length = 0 means invalid file + fhdr.file_length = 0; + output.write((char*)&fhdr, sizeof(ramfs_file_header)); + continue; + } + + fhdr.name_length = name.size(); + fhdr.file_length = 0; + while (!infile.eof()) { + char c; + infile.read(&c, 1); + fhdr.file_length++; + } + + infile.close(); infile.open(file.c_str(), ios::in | ios::binary); //Rewind file + + output.write((char*)&fhdr, sizeof(ramfs_file_header)); + + output << name; + output << '\0'; + + char *c = new char[fhdr.file_length]; + for (int i = 0; i < fhdr.file_length; i++) { + char ch; + infile.read(&ch, 1); + output.write(&ch, 1); + } + delete [] c; + + infile.close(); + } + + output.close(); + + return 0; +} |