From f0893a62d46605305ae14baba6cae3eebffc6005 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Thu, 19 Aug 2010 15:21:17 +0100 Subject: [PATCH] Add -f ext2 option. This option doesn't work yet. The commit is just for adding the capability to pass the extra kernel/initrd/appliance parameters through 'main.c' and 'appliance.c'. --- helper/Makefile.am | 1 + helper/appliance.c | 3 ++- helper/cpio.c | 3 ++- helper/ext2.c | 46 ++++++++++++++++++++++++++++++++++ helper/febootstrap-supermin-helper.pod | 38 ++++++++++++++++++++++------ helper/helper.h | 16 +++++++++--- helper/main.c | 43 +++++++++++++++++++++++-------- 7 files changed, 127 insertions(+), 23 deletions(-) create mode 100644 helper/ext2.c diff --git a/helper/Makefile.am b/helper/Makefile.am index 9702bbe..3af1d64 100644 --- a/helper/Makefile.am +++ b/helper/Makefile.am @@ -24,6 +24,7 @@ febootstrap_supermin_helper_SOURCES = \ helper.h \ appliance.c \ cpio.c \ + ext2.c \ kernel.c \ main.c \ utils.c diff --git a/helper/appliance.c b/helper/appliance.c index b7a46c0..2474b14 100644 --- a/helper/appliance.c +++ b/helper/appliance.c @@ -68,10 +68,11 @@ void create_appliance (char **inputs, int nr_inputs, const char *whitelist, const char *modpath, + const char *initrd, const char *appliance, struct writer *writer) { - writer->wr_start (appliance); + writer->wr_start (appliance, modpath, initrd); iterate_inputs (inputs, nr_inputs, writer); diff --git a/helper/cpio.c b/helper/cpio.c index f9ffc3f..1dd22b0 100644 --- a/helper/cpio.c +++ b/helper/cpio.c @@ -250,7 +250,8 @@ write_padding (size_t len) } static void -cpio_start (const char *appliance) +cpio_start (const char *appliance, + const char *modpath, const char *initrd) { out_fd = open (appliance, O_WRONLY | O_CREAT | O_TRUNC | O_NOCTTY, 0644); if (out_fd == -1) diff --git a/helper/ext2.c b/helper/ext2.c new file mode 100644 index 0000000..2900221 --- /dev/null +++ b/helper/ext2.c @@ -0,0 +1,46 @@ +/* febootstrap-supermin-helper reimplementation in C. + * Copyright (C) 2009-2010 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include + +#include +#include +#include +#include +#include + +#include "error.h" +#include "fts_.h" + +#include "helper.h" + +static void +ext2_start (const char *appliance, + const char *modpath, const char *initrd) +{ + abort (); +} + +struct writer ext2_writer = { + .wr_start = ext2_start, + /* .wr_end = , + .wr_file = , + .wr_file_stat = , + .wr_fts_entry = , + .wr_cpio_file = , */ +}; diff --git a/helper/febootstrap-supermin-helper.pod b/helper/febootstrap-supermin-helper.pod index 6a2551b..7a3dbd1 100644 --- a/helper/febootstrap-supermin-helper.pod +++ b/helper/febootstrap-supermin-helper.pod @@ -7,6 +7,8 @@ febootstrap-supermin-helper - Reconstruct initramfs from supermin appliance. febootstrap-supermin-helper supermin.img hostfiles.txt host_cpu kernel initrd febootstrap-supermin-helper input [...] host_cpu kernel initrd + febootstrap-supermin-helper -f ext2 input [...] host_cpu kernel initrd appliance + =head1 DESCRIPTION I reconstructs a bootable kernel and @@ -16,8 +18,8 @@ L. =head1 PARAMETERS -Of the four or five required parameters, the first few are I -files, and the last two are I files. +Of the required parameters, the first few are I files, and the +last two or three are I files. C and C are the input files which describe the supermin appliance. (You can also use a directory name @@ -25,18 +27,38 @@ here which is searched for files). C should be the host CPU, eg. C or C. -C and C are the temporary output files that this -script produces. These output files are meant to be used just for -booting the appliance, and should be deleted straight afterwards. +C, C and C are the temporary output files +that this script produces. These output files are meant to be used +just for booting the appliance, and should be deleted straight +afterwards. The extra C parameter is only required when +the format is C. =head1 OPTIONS =over 4 -=item B<-f cpio> | B<--format cpio> +=item B<-f fmt> | B<--format fmt> + +Select the output format for the appliance. Possible formats are: + +=over 4 + +=item cpio + +A Linux initramfs. This is the default. -Select the output format. The default, and only possible output -format, is C (ie. a Linux initramfs). +In this case you have to supply names for the C +and C, where the C is the appliance. + +=item ext2 + +An ext2 filesystem. + +In this case you have to supply names for the C, +a small C which is used just to locate the appliance, +and the C (the ext2 filesystem). + +=back =item B<-k file> | B<--kmods file> diff --git a/helper/helper.h b/helper/helper.h index 9bb637a..cb28695 100644 --- a/helper/helper.h +++ b/helper/helper.h @@ -23,8 +23,15 @@ #include "fts_.h" struct writer { - /* Start a new appliance, finish one off. */ - void (*wr_start) (const char *appliance); + /* Start building a new appliance. + * 'appliance' is the output appliance. + * 'initrd' is the mini-initrd to create (only used for ext2 output). + * 'modpath' is the kernel module path. + */ + void (*wr_start) (const char *appliance, + const char *modpath, const char *initrd); + + /* Finish off the appliance. */ void (*wr_end) (void); /* Append the named host file to the appliance being built. The @@ -45,11 +52,14 @@ extern struct timeval start_t; extern int verbose; /* appliance.c */ -extern void create_appliance (char **inputs, int nr_inputs, const char *whitelist, const char *modpath, const char *appliance, struct writer *writer); +extern void create_appliance (char **inputs, int nr_inputs, const char *whitelist, const char *modpath, const char *initrd, const char *appliance, struct writer *writer); /* cpio.c */ extern struct writer cpio_writer; +/* ext2.c */ +extern struct writer ext2_writer; + /* kernel.c */ extern const char *create_kernel (const char *hostcpu, const char *kernel); diff --git a/helper/main.c b/helper/main.c index f5a06cc..f8bf41d 100644 --- a/helper/main.c +++ b/helper/main.c @@ -57,6 +57,7 @@ usage (const char *progname) "\n" "Usage:\n" " %s [-options] inputs [...] whitelist host_cpu kernel initrd\n" + " %s -f ext2 inputs [...] whitelist host_cpu kernel initrd appliance\n" " %s --help\n" " %s --version\n" "\n" @@ -79,7 +80,7 @@ usage (const char *progname) " Enable verbose messages (give multiple times for more verbosity).\n" " --version | -V\n" " Display version number and exit.\n", - progname, progname, progname, progname); + progname, progname, progname, progname, progname); } int @@ -124,37 +125,56 @@ main (int argc, char *argv[]) /* Select the correct writer module. */ struct writer *writer; + int nr_outputs; - if (strcmp (format, "cpio") == 0) + if (strcmp (format, "cpio") == 0) { writer = &cpio_writer; + nr_outputs = 2; /* kernel and appliance (== initrd) */ + } + else if (strcmp (format, "ext2") == 0) { + writer = &ext2_writer; + nr_outputs = 3; /* kernel, initrd, appliance */ + } else { fprintf (stderr, "%s: incorrect output format (-f): must be cpio\n", argv[0]); exit (EXIT_FAILURE); } + /* [optind .. optind+nr_inputs-1] hostcpu [argc-nr_outputs-1 .. argc-1] + * <---- nr_inputs ----> 1 <---- nr_outputs ----> + */ char **inputs = &argv[optind]; - int nr_inputs = argc - optind - 3; + int nr_inputs = argc - nr_outputs - 1 - optind; + char **outputs = &argv[optind+nr_inputs+1]; + /*assert (outputs [nr_outputs] == NULL); + assert (inputs [nr_inputs + 1 + nr_outputs] == NULL);*/ if (nr_inputs < 1) { - usage (argv[0]); + fprintf (stderr, "%s: not enough files specified on the command line\n", + argv[0]); exit (EXIT_FAILURE); } /* See: https://bugzilla.redhat.com/show_bug.cgi?id=558593 */ - const char *hostcpu = argv[argc-3]; + const char *hostcpu = outputs[-1]; /* Output files. */ - const char *kernel = argv[argc-2]; - const char *appliance = argv[argc-1]; + const char *kernel = outputs[0]; + const char *initrd; + const char *appliance; + initrd = appliance = outputs[1]; + if (nr_outputs > 2) + appliance = outputs[2]; if (verbose) { print_timestamped_message ("whitelist = %s, " "host_cpu = %s, " "kernel = %s, " + "initrd = %s, " "appliance = %s", whitelist ? : "(not specified)", - hostcpu, kernel, appliance); + hostcpu, kernel, initrd, appliance); int i; for (i = 0; i < nr_inputs; ++i) print_timestamped_message ("inputs[%d] = %s", i, inputs[i]); @@ -162,7 +182,9 @@ main (int argc, char *argv[]) /* Remove the output files if they exist. */ unlink (kernel); - unlink (appliance); + unlink (initrd); + if (initrd != appliance) + unlink (appliance); /* Create kernel output file. */ const char *modpath; @@ -172,7 +194,8 @@ main (int argc, char *argv[]) print_timestamped_message ("finished creating kernel"); /* Create the appliance. */ - create_appliance (inputs, nr_inputs, whitelist, modpath, appliance, writer); + create_appliance (inputs, nr_inputs, whitelist, modpath, + initrd, appliance, writer); if (verbose) print_timestamped_message ("finished creating appliance"); -- 1.8.3.1