images/100kallspaces
images/100krandom
images/10klines
+images/initrd
images/test.sqsh
initramfs
initramfs.timestamp
guestfsd.c \
headtail.c \
hexdump.c \
+ initrd.c \
ls.c \
lvm.c \
mount.c \
--- /dev/null
+/* libguestfs - the guestfsd daemon
+ * Copyright (C) 2009 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 <unistd.h>
+
+#include "../src/guestfs_protocol.h"
+#include "daemon.h"
+#include "actions.h"
+
+char **
+do_initrd_list (char *path)
+{
+ FILE *fp;
+ int len;
+ char *cmd;
+ char filename[PATH_MAX];
+ char **filenames = NULL;
+ int size = 0, alloc = 0;
+
+ NEED_ROOT (NULL);
+ ABS_PATH (path, NULL);
+
+ /* "zcat /sysroot/<path> | cpio --quiet -it", but path must be quoted. */
+ len = 64 + 2 * strlen (path);
+ cmd = malloc (len);
+ if (!cmd) {
+ reply_with_perror ("malloc");
+ return NULL;
+ }
+
+ strcpy (cmd, "zcat /sysroot");
+ shell_quote (cmd+13, len-13, path);
+ strcat (cmd, " | cpio --quiet -it");
+
+ fprintf (stderr, "%s\n", cmd);
+
+ fp = popen (cmd, "r");
+ if (fp == NULL) {
+ reply_with_perror ("popen: %s", cmd);
+ free (cmd);
+ return NULL;
+ }
+ free (cmd);
+
+ while (fgets (filename, sizeof filename, fp) != NULL) {
+ len = strlen (filename);
+ if (len > 0 && filename[len-1] == '\n')
+ filename[len-1] = '\0';
+
+ if (add_string (&filenames, &size, &alloc, filename) == -1) {
+ pclose (fp);
+ return NULL;
+ }
+ }
+
+ if (add_string (&filenames, &size, &alloc, NULL) == -1) {
+ pclose (fp);
+ return NULL;
+ }
+
+ if (pclose (fp) == -1) {
+ reply_with_perror ("pclose");
+ free_strings (filenames);
+ return NULL;
+ }
+
+ return filenames;
+}
CLEANFILES = test.sqsh
squash_files = helloworld.tar helloworld.tar.gz empty known-1 known-2 known-3 \
- 100kallzeroes 100kallnewlines 100kallspaces 100krandom 10klines
+ 100kallzeroes 100kallnewlines 100kallspaces 100krandom 10klines \
+ initrd
test.sqsh: $(squash_files)
rm -f $@
i=$$(($$i+1)); \
done > $@-t
mv $@-t $@
+
+initrd: empty known-1 known-2 known-3
+ rm -f $@ $@-t
+ for f in $^; do echo $$f; done | cpio -o -H newc | gzip --best > $@-t
+ mv $@-t $@
# we don't need to know.
if ($output !~ /.*fish$/) {
- # Temporary directory for use by check_for_initrd.
- my $dir = tempdir (CLEANUP => 1);
-
my $root_dev;
foreach $root_dev (sort keys %oses) {
my $mounts = $oses{$root_dev}->{mounts};
check_for_kernels ($root_dev);
if ($oses{$root_dev}->{os} eq "linux") {
check_for_modprobe_aliases ($root_dev);
- check_for_initrd ($root_dev, $dir);
+ check_for_initrd ($root_dev);
}
$g->umount_all ();
{
local $_;
my $root_dev = shift;
- my $dir = shift;
my %initrd_modules;
foreach my $initrd ($g->ls ("/boot")) {
if ($initrd =~ m/^initrd-(.*)\.img$/ && $g->is_file ("/boot/$initrd")) {
my $version = $1;
- my @modules = ();
- # We have to download these to a temporary file.
- $g->download ("/boot/$initrd", "$dir/initrd");
-
- my $cmd = "zcat $dir/initrd | file -";
- open P, "$cmd |" or die "$cmd: $!";
- my $lines;
- { local $/ = undef; $lines = <P>; }
- close P;
- if ($lines =~ /ext\d filesystem data/) {
- # Before initramfs came along, these were compressed
- # ext2 filesystems. We could run another libguestfs
- # instance to unpack these, but punt on them for now. (XXX)
- warn "initrd image is unsupported ext2/3/4 filesystem\n";
- }
- elsif ($lines =~ /cpio/) {
- my $cmd = "zcat $dir/initrd | cpio --quiet -it";
- open P, "$cmd |" or die "$cmd: $!";
- while (<P>) {
- push @modules, $1
- if m,([^/]+)\.ko$, || m,([^/]+)\.o$,;
- }
- close P;
- unlink "$dir/initrd";
- $initrd_modules{$version} = \@modules;
- }
- else {
- # What?
- warn "unrecognized initrd image: $lines\n";
+ my @modules;
+
+ eval {
+ @modules = $g->initrd_list ("/boot/$initrd");
+ };
+ unless ($@) {
+ @modules = grep { m,([^/]+)\.ko$, || m,([^/]+)\.o$, } @modules;
+ $initrd_modules{$version} = \@modules
+ } else {
+ warn "/boot/$initrd: could not read initrd format"
}
}
}
The result is the estimated size in I<kilobytes>
(ie. units of 1024 bytes).");
+ ("initrd_list", (RStringList "filenames", [String "path"]), 128, [],
+ [InitBasicFS, Always, TestOutputList (
+ [["mount_vfs"; "ro"; "squashfs"; "/dev/sdd"; "/"];
+ ["initrd_list"; "/initrd"]], ["empty";"known-1";"known-2";"known-3"])],
+ "list files in an initrd",
+ "\
+This command lists out files contained in an initrd.
+
+The files are listed without any initial C</> character. The
+files are listed in the order they appear (not necessarily
+alphabetical). Directory names are listed as separate items.
+
+Old Linux kernels (2.4 and earlier) used a compressed ext2
+filesystem as initrd. We I<only> support the newer initramfs
+format (compressed cpio files).");
+
]
let all_functions = non_daemon_functions @ daemon_functions