helper.h \
appliance.c \
cpio.c \
+ ext2.c \
kernel.c \
main.c \
utils.c
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);
}
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)
--- /dev/null
+/* 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 <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <assert.h>
+
+#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 = , */
+};
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<febootstrap-supermin-helper> reconstructs a bootable kernel and
=head1 PARAMETERS
-Of the four or five required parameters, the first few are I<input>
-files, and the last two are I<output> files.
+Of the required parameters, the first few are I<input> files, and the
+last two or three are I<output> files.
C<supermin.img> and C<hostfiles.txt> are the input files which
describe the supermin appliance. (You can also use a directory name
C<host_cpu> should be the host CPU, eg. C<x86_64> or C<i686>.
-C<kernel> and C<initrd> 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<kernel>, C<initrd> and C<appliance> 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<appliance> parameter is only required when
+the format is C<ext2>.
=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<cpio> (ie. a Linux initramfs).
+In this case you have to supply names for the C<kernel>
+and C<initrd>, where the C<initrd> is the appliance.
+
+=item ext2
+
+An ext2 filesystem.
+
+In this case you have to supply names for the C<kernel>,
+a small C<initrd> which is used just to locate the appliance,
+and the C<appliance> (the ext2 filesystem).
+
+=back
=item B<-k file> | B<--kmods file>
#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
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);
"\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"
" 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
/* 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]);
/* 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;
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");