/* * Copyright 2010 Stefan Lankes, Chair for Operating Systems, * RWTH Aachen University * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * This file is part of MetalSVM. */ #include #include #include #include #define INITRD_MAGIC_NUMBER 0x4711 #define MAX_FNAME 128 #define PAGE_SIZE 4096 typedef struct { uint32_t magic; uint32_t nfiles; char mount_point[MAX_FNAME]; } initrd_header_t; typedef struct { uint32_t length; uint32_t offset; char fname[MAX_FNAME]; } initrd_file_desc_t; static void print_options(void) { printf(" make_initrd mount_point path name [path name]\n"); printf("\n"); printf(" mount_point - mount point of init ram disk, where all file will be mounted.\n"); printf(" path - path to the file, which will be mounted\n"); printf(" name - file name, which will be used be the initrd\n"); } int main(int argc, char **argv) { int i, nfiles = (argc - 2) / 2; initrd_header_t header; initrd_file_desc_t* file_desc; off_t offset; FILE* istream; FILE* ostream; if ((argc < 4) || (strcmp(argv[1], "-h") == 0)) { print_options(); return 0; } memset(&header, 0x00, sizeof(initrd_header_t)); header.magic = INITRD_MAGIC_NUMBER; header.nfiles = nfiles; strncpy(header.mount_point, argv[1], MAX_FNAME); file_desc = (initrd_file_desc_t*) malloc(sizeof(initrd_file_desc_t)*nfiles); if (!file_desc) { fprintf(stderr, "No enough memory\n"); return -1; } memset(file_desc, 0x00, sizeof(initrd_file_desc_t)*nfiles); offset = sizeof(initrd_header_t) + nfiles * sizeof(initrd_file_desc_t); for(i=0; i 0); fclose(istream); free(buf); } fclose(ostream); return 0; }