summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Booth <mbooth@redhat.com>2009-06-29 16:27:05 +0100
committerMatthew Booth <mbooth@redhat.com>2009-06-29 16:27:05 +0100
commit128f822e16bb96677c75b88125e18f48d7ccedaf (patch)
treec5f09d72e73c90c02967f48151831e6c4a78fb68
parent103fb55e6b1428366ab31a0f17484ef1baa68e96 (diff)
parentad475104ec7fae456d3309cbf4261b893ed160bb (diff)
downloadlibguestfs-128f822e16bb96677c75b88125e18f48d7ccedaf.tar.gz
libguestfs-128f822e16bb96677c75b88125e18f48d7ccedaf.tar.xz
libguestfs-128f822e16bb96677c75b88125e18f48d7ccedaf.zip
Merge commit 'et/master'
-rw-r--r--.gitignore1
-rw-r--r--TODO13
-rw-r--r--capitests/tests.c164
-rw-r--r--daemon/Makefile.am1
-rw-r--r--daemon/actions.h2
-rw-r--r--daemon/initrd.c88
-rw-r--r--daemon/mount.c45
-rw-r--r--daemon/stubs.c60
-rw-r--r--fish/cmds.c47
-rw-r--r--fish/completion.c2
-rw-r--r--guestfish-actions.pod22
-rw-r--r--guestfs-actions.pod31
-rw-r--r--haskell/Guestfs.hs15
-rw-r--r--images/Makefile.am8
-rwxr-xr-xinspector/virt-inspector.pl45
-rw-r--r--java/com/redhat/et/libguestfs/GuestFS.java45
-rw-r--r--java/com_redhat_et_libguestfs_GuestFS.c53
-rw-r--r--ocaml/guestfs.ml2
-rw-r--r--ocaml/guestfs.mli6
-rw-r--r--ocaml/guestfs_c_actions.c50
-rw-r--r--perl/Guestfs.xs31
-rw-r--r--perl/lib/Sys/Guestfs.pm18
-rw-r--r--python/guestfs-py.c53
-rw-r--r--python/guestfs.py23
-rw-r--r--ruby/ext/guestfs/_guestfs.c61
-rw-r--r--src/MAX_PROC_NR2
-rwxr-xr-xsrc/generator.ml24
-rw-r--r--src/guestfs-actions.c186
-rw-r--r--src/guestfs-actions.h2
-rw-r--r--src/guestfs.c7
-rw-r--r--src/guestfs_protocol.c33
-rw-r--r--src/guestfs_protocol.h29
-rw-r--r--src/guestfs_protocol.x15
33 files changed, 1143 insertions, 41 deletions
diff --git a/.gitignore b/.gitignore
index bbb1045b..4d1da443 100644
--- a/.gitignore
+++ b/.gitignore
@@ -67,6 +67,7 @@ images/100kallnewlines
images/100kallspaces
images/100krandom
images/10klines
+images/initrd
images/test.sqsh
initramfs
initramfs.timestamp
diff --git a/TODO b/TODO
index 48628f5e..eb5820ff 100644
--- a/TODO
+++ b/TODO
@@ -157,3 +157,16 @@ Extra commands / functionality:
----------------------------------------------------------------------
Allow swap space from the guest to be used. Is it a good idea?
+
+----------------------------------------------------------------------
+
+Need a way to query a binary or library file for its architecture.
+Using objdump or readelf?
+What about non-ELF files (eg. Windows, BSD).
+
+----------------------------------------------------------------------
+
+Other initrd-* commands, such as:
+
+initrd-extract
+initrd-replace
diff --git a/capitests/tests.c b/capitests/tests.c
index 6e31c401..455c20e3 100644
--- a/capitests/tests.c
+++ b/capitests/tests.c
@@ -153,6 +153,162 @@ static void no_test_warnings (void)
fprintf (stderr, "warning: \"guestfs_scrub_freespace\" has no tests\n");
fprintf (stderr, "warning: \"guestfs_df\" has no tests\n");
fprintf (stderr, "warning: \"guestfs_df_h\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_mount_loop\" has no tests\n");
+}
+
+static int test_initrd_list_0_skip (void)
+{
+ const char *str;
+
+ str = getenv ("TEST_ONLY");
+ if (str)
+ return strstr (str, "initrd_list") == NULL;
+ str = getenv ("SKIP_TEST_INITRD_LIST_0");
+ if (str && strcmp (str, "1") == 0) return 1;
+ str = getenv ("SKIP_TEST_INITRD_LIST");
+ if (str && strcmp (str, "1") == 0) return 1;
+ return 0;
+}
+
+static int test_initrd_list_0 (void)
+{
+ if (test_initrd_list_0_skip ()) {
+ printf ("%s skipped (reason: environment variable set)\n", "test_initrd_list_0");
+ return 0;
+ }
+
+ /* InitBasicFS for test_initrd_list_0: create ext2 on /dev/sda1 */
+ {
+ char device[] = "/dev/sda";
+ int r;
+ suppress_error = 0;
+ r = guestfs_blockdev_setrw (g, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ int r;
+ suppress_error = 0;
+ r = guestfs_umount_all (g);
+ if (r == -1)
+ return -1;
+ }
+ {
+ int r;
+ suppress_error = 0;
+ r = guestfs_lvm_remove_all (g);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char device[] = "/dev/sda";
+ char lines_0[] = ",";
+ char *lines[] = {
+ lines_0,
+ NULL
+ };
+ int r;
+ suppress_error = 0;
+ r = guestfs_sfdisk (g, device, 0, 0, 0, lines);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char fstype[] = "ext2";
+ char device[] = "/dev/sda1";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mkfs (g, fstype, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char device[] = "/dev/sda1";
+ char mountpoint[] = "/";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mount (g, device, mountpoint);
+ if (r == -1)
+ return -1;
+ }
+ /* TestOutputList for initrd_list (0) */
+ {
+ char options[] = "ro";
+ char vfstype[] = "squashfs";
+ char device[] = "/dev/sdd";
+ char mountpoint[] = "/";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mount_vfs (g, options, vfstype, device, mountpoint);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char path[] = "/initrd";
+ char **r;
+ int i;
+ suppress_error = 0;
+ r = guestfs_initrd_list (g, path);
+ if (r == NULL)
+ return -1;
+ if (!r[0]) {
+ fprintf (stderr, "test_initrd_list_0: short list returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ {
+ char expected[] = "empty";
+ if (strcmp (r[0], expected) != 0) {
+ fprintf (stderr, "test_initrd_list_0: expected \"%s\" but got \"%s\"\n", expected, r[0]);
+ return -1;
+ }
+ }
+ if (!r[1]) {
+ fprintf (stderr, "test_initrd_list_0: short list returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ {
+ char expected[] = "known-1";
+ if (strcmp (r[1], expected) != 0) {
+ fprintf (stderr, "test_initrd_list_0: expected \"%s\" but got \"%s\"\n", expected, r[1]);
+ return -1;
+ }
+ }
+ if (!r[2]) {
+ fprintf (stderr, "test_initrd_list_0: short list returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ {
+ char expected[] = "known-2";
+ if (strcmp (r[2], expected) != 0) {
+ fprintf (stderr, "test_initrd_list_0: expected \"%s\" but got \"%s\"\n", expected, r[2]);
+ return -1;
+ }
+ }
+ if (!r[3]) {
+ fprintf (stderr, "test_initrd_list_0: short list returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ {
+ char expected[] = "known-3";
+ if (strcmp (r[3], expected) != 0) {
+ fprintf (stderr, "test_initrd_list_0: expected \"%s\" but got \"%s\"\n", expected, r[3]);
+ return -1;
+ }
+ }
+ if (r[4] != NULL) {
+ fprintf (stderr, "test_initrd_list_0: extra elements returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ for (i = 0; r[i] != NULL; ++i)
+ free (r[i]);
+ free (r);
+ }
+ return 0;
}
static int test_du_0_skip (void)
@@ -18608,9 +18764,15 @@ int main (int argc, char *argv[])
/* Cancel previous alarm. */
alarm (0);
- nr_tests = 165;
+ nr_tests = 166;
test_num++;
+ printf ("%3d/%3d test_initrd_list_0\n", test_num, nr_tests);
+ if (test_initrd_list_0 () == -1) {
+ printf ("test_initrd_list_0 FAILED\n");
+ failed++;
+ }
+ test_num++;
printf ("%3d/%3d test_du_0\n", test_num, nr_tests);
if (test_du_0 () == -1) {
printf ("test_du_0 FAILED\n");
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index 2884e936..88c382cf 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -43,6 +43,7 @@ guestfsd_SOURCES = \
guestfsd.c \
headtail.c \
hexdump.c \
+ initrd.c \
ls.c \
lvm.c \
mount.c \
diff --git a/daemon/actions.h b/daemon/actions.h
index 7d87b677..1d412dcc 100644
--- a/daemon/actions.h
+++ b/daemon/actions.h
@@ -148,3 +148,5 @@ extern char **do_tail_n (int nrlines, char *path);
extern char *do_df (void);
extern char *do_df_h (void);
extern int64_t do_du (char *path);
+extern char **do_initrd_list (char *path);
+extern int do_mount_loop (char *file, char *mountpoint);
diff --git a/daemon/initrd.c b/daemon/initrd.c
new file mode 100644
index 00000000..513ed8da
--- /dev/null
+++ b/daemon/initrd.c
@@ -0,0 +1,88 @@
+/* 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;
+}
diff --git a/daemon/mount.c b/daemon/mount.c
index 4955fcf3..b0cb496e 100644
--- a/daemon/mount.c
+++ b/daemon/mount.c
@@ -71,6 +71,7 @@ do_mount_vfs (char *options, char *vfstype,
else
r = command (NULL, &error,
"mount", "-o", options, device, mp, NULL);
+ free (mp);
if (r == -1) {
reply_with_error ("mount: %s on %s: %s", device, mountpoint, error);
free (error);
@@ -277,3 +278,47 @@ do_umount_all (void)
return 0;
}
+
+/* Mount using the loopback device. You can't use the generic
+ * do_mount call for this because the first parameter isn't a
+ * device.
+ */
+int
+do_mount_loop (char *file, char *mountpoint)
+{
+ int len, r;
+ char *buf, *mp;
+ char *error;
+
+ NEED_ROOT (-1);
+ ABS_PATH (file, -1);
+
+ /* We have to prefix /sysroot on both the filename and the mountpoint. */
+ len = strlen (mountpoint) + 9;
+ mp = malloc (len);
+ if (!mp) {
+ reply_with_perror ("malloc");
+ return -1;
+ }
+ snprintf (mp, len, "/sysroot%s", mountpoint);
+
+ len = strlen (file) + 9;
+ buf = malloc (len);
+ if (!file) {
+ reply_with_perror ("malloc");
+ free (mp);
+ return -1;
+ }
+ snprintf (buf, len, "/sysroot%s", file);
+
+ r = command (NULL, &error, "mount", "-o", "loop", buf, mp, NULL);
+ free (mp);
+ free (buf);
+ if (r == -1) {
+ reply_with_error ("mount: %s on %s: %s", file, mountpoint, error);
+ free (error);
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/daemon/stubs.c b/daemon/stubs.c
index 67e6ef5b..6d7cb0e7 100644
--- a/daemon/stubs.c
+++ b/daemon/stubs.c
@@ -3205,6 +3205,60 @@ done:
xdr_free ((xdrproc_t) xdr_guestfs_du_args, (char *) &args);
}
+static void initrd_list_stub (XDR *xdr_in)
+{
+ char **r;
+ struct guestfs_initrd_list_args args;
+ char *path;
+
+ memset (&args, 0, sizeof args);
+
+ if (!xdr_guestfs_initrd_list_args (xdr_in, &args)) {
+ reply_with_error ("%s: daemon failed to decode procedure arguments", "initrd_list");
+ return;
+ }
+ path = args.path;
+
+ r = do_initrd_list (path);
+ if (r == NULL)
+ /* do_initrd_list has already called reply_with_error */
+ goto done;
+
+ struct guestfs_initrd_list_ret ret;
+ ret.filenames.filenames_len = count_strings (r);
+ ret.filenames.filenames_val = r;
+ reply ((xdrproc_t) &xdr_guestfs_initrd_list_ret, (char *) &ret);
+ free_strings (r);
+done:
+ xdr_free ((xdrproc_t) xdr_guestfs_initrd_list_args, (char *) &args);
+}
+
+static void mount_loop_stub (XDR *xdr_in)
+{
+ int r;
+ struct guestfs_mount_loop_args args;
+ char *file;
+ char *mountpoint;
+
+ memset (&args, 0, sizeof args);
+
+ if (!xdr_guestfs_mount_loop_args (xdr_in, &args)) {
+ reply_with_error ("%s: daemon failed to decode procedure arguments", "mount_loop");
+ return;
+ }
+ file = args.file;
+ mountpoint = args.mountpoint;
+
+ r = do_mount_loop (file, mountpoint);
+ if (r == -1)
+ /* do_mount_loop has already called reply_with_error */
+ goto done;
+
+ reply (NULL, NULL);
+done:
+ xdr_free ((xdrproc_t) xdr_guestfs_mount_loop_args, (char *) &args);
+}
+
void dispatch_incoming_message (XDR *xdr_in)
{
switch (proc_nr) {
@@ -3589,6 +3643,12 @@ void dispatch_incoming_message (XDR *xdr_in)
case GUESTFS_PROC_DU:
du_stub (xdr_in);
break;
+ case GUESTFS_PROC_INITRD_LIST:
+ initrd_list_stub (xdr_in);
+ break;
+ case GUESTFS_PROC_MOUNT_LOOP:
+ mount_loop_stub (xdr_in);
+ break;
default:
reply_with_error ("dispatch_incoming_message: unknown procedure number %d, set LIBGUESTFS_PATH to point to the matching libguestfs appliance directory", proc_nr);
}
diff --git a/fish/cmds.c b/fish/cmds.c
index c802f90b..c9c05158 100644
--- a/fish/cmds.c
+++ b/fish/cmds.c
@@ -92,6 +92,7 @@ void list_commands (void)
printf ("%-20s %s\n", "head", "return first 10 lines of a file");
printf ("%-20s %s\n", "head-n", "return first N lines of a file");
printf ("%-20s %s\n", "hexdump", "dump a file in hexadecimal");
+ printf ("%-20s %s\n", "initrd-list", "list files in an initrd");
printf ("%-20s %s\n", "is-busy", "is busy processing a command");
printf ("%-20s %s\n", "is-config", "is in configuration state");
printf ("%-20s %s\n", "is-dir", "test if file exists");
@@ -116,6 +117,7 @@ void list_commands (void)
printf ("%-20s %s\n", "mkdtemp", "create a temporary directory");
printf ("%-20s %s\n", "mkfs", "make a filesystem");
printf ("%-20s %s\n", "mount", "mount a guest disk at a position in the filesystem");
+ printf ("%-20s %s\n", "mount-loop", "mount a file using the loop device");
printf ("%-20s %s\n", "mount-options", "mount a guest disk with mount options");
printf ("%-20s %s\n", "mount-ro", "mount a guest disk, read-only");
printf ("%-20s %s\n", "mount-vfs", "mount a guest disk with mount options and vfstype");
@@ -628,6 +630,12 @@ void display_command (const char *cmd)
if (strcasecmp (cmd, "du") == 0)
pod2text ("du - estimate file space usage", " du <path>\n\nThis command runs the C<du -s> command to estimate file space\nusage for C<path>.\n\nC<path> can be a file or a directory. If C<path> is a directory\nthen the estimate includes the contents of the directory and all\nsubdirectories (recursively).\n\nThe result is the estimated size in I<kilobytes>\n(ie. units of 1024 bytes).");
else
+ if (strcasecmp (cmd, "initrd_list") == 0 || strcasecmp (cmd, "initrd-list") == 0)
+ pod2text ("initrd-list - list files in an initrd", " initrd-list <path>\n\nThis command lists out files contained in an initrd.\n\nThe files are listed without any initial C</> character. The\nfiles are listed in the order they appear (not necessarily\nalphabetical). Directory names are listed as separate items.\n\nOld Linux kernels (2.4 and earlier) used a compressed ext2\nfilesystem as initrd. We I<only> support the newer initramfs\nformat (compressed cpio files).");
+ else
+ if (strcasecmp (cmd, "mount_loop") == 0 || strcasecmp (cmd, "mount-loop") == 0)
+ pod2text ("mount-loop - mount a file using the loop device", " mount-loop <file> <mountpoint>\n\nThis command lets you mount C<file> (a filesystem image\nin a file) on a mount point. It is entirely equivalent to\nthe command C<mount -o loop file mountpoint>.");
+ else
display_builtin_command (cmd);
}
@@ -3082,6 +3090,39 @@ static int run_du (const char *cmd, int argc, char *argv[])
return 0;
}
+static int run_initrd_list (const char *cmd, int argc, char *argv[])
+{
+ char **r;
+ const char *path;
+ if (argc != 1) {
+ fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
+ fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
+ return -1;
+ }
+ path = argv[0];
+ r = guestfs_initrd_list (g, path);
+ if (r == NULL) return -1;
+ print_strings (r);
+ free_strings (r);
+ return 0;
+}
+
+static int run_mount_loop (const char *cmd, int argc, char *argv[])
+{
+ int r;
+ const char *file;
+ const char *mountpoint;
+ if (argc != 2) {
+ fprintf (stderr, "%s should have 2 parameter(s)\n", cmd);
+ fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
+ return -1;
+ }
+ file = argv[0];
+ mountpoint = argv[1];
+ r = guestfs_mount_loop (g, file, mountpoint);
+ return r;
+}
+
int run_action (const char *cmd, int argc, char *argv[])
{
if (strcasecmp (cmd, "launch") == 0 || strcasecmp (cmd, "run") == 0)
@@ -3528,6 +3569,12 @@ int run_action (const char *cmd, int argc, char *argv[])
if (strcasecmp (cmd, "du") == 0)
return run_du (cmd, argc, argv);
else
+ if (strcasecmp (cmd, "initrd_list") == 0 || strcasecmp (cmd, "initrd-list") == 0)
+ return run_initrd_list (cmd, argc, argv);
+ else
+ if (strcasecmp (cmd, "mount_loop") == 0 || strcasecmp (cmd, "mount-loop") == 0)
+ return run_mount_loop (cmd, argc, argv);
+ else
{
fprintf (stderr, "%s: unknown command\n", cmd);
return -1;
diff --git a/fish/completion.c b/fish/completion.c
index 5254a373..2ddfb433 100644
--- a/fish/completion.c
+++ b/fish/completion.c
@@ -194,6 +194,8 @@ static const char *const commands[] = {
"df",
"df-h",
"du",
+ "initrd-list",
+ "mount-loop",
NULL
};
diff --git a/guestfish-actions.pod b/guestfish-actions.pod
index 9f625c71..a3592ad4 100644
--- a/guestfish-actions.pod
+++ b/guestfish-actions.pod
@@ -778,6 +778,20 @@ Because of the message protocol, there is a transfer limit
of somewhere between 2MB and 4MB. To transfer large files you should use
FTP.
+=head2 initrd-list
+
+ initrd-list path
+
+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).
+
=head2 is-busy
is-busy
@@ -1021,6 +1035,14 @@ on the underlying device.
The filesystem options C<sync> and C<noatime> are set with this
call, in order to improve reliability.
+=head2 mount-loop
+
+ mount-loop file mountpoint
+
+This command lets you mount C<file> (a filesystem image
+in a file) on a mount point. It is entirely equivalent to
+the command C<mount -o loop file mountpoint>.
+
=head2 mount-options
mount-options options device mountpoint
diff --git a/guestfs-actions.pod b/guestfs-actions.pod
index 039608d5..56949faa 100644
--- a/guestfs-actions.pod
+++ b/guestfs-actions.pod
@@ -1012,6 +1012,25 @@ Because of the message protocol, there is a transfer limit
of somewhere between 2MB and 4MB. To transfer large files you should use
FTP.
+=head2 guestfs_initrd_list
+
+ char **guestfs_initrd_list (guestfs_h *handle,
+ const char *path);
+
+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).
+
+This function returns a NULL-terminated array of strings
+(like L<environ(3)>), or NULL if there was an error.
+I<The caller must free the strings and the array after use>.
+
=head2 guestfs_is_busy
int guestfs_is_busy (guestfs_h *handle);
@@ -1337,6 +1356,18 @@ call, in order to improve reliability.
This function returns 0 on success or -1 on error.
+=head2 guestfs_mount_loop
+
+ int guestfs_mount_loop (guestfs_h *handle,
+ const char *file,
+ const char *mountpoint);
+
+This command lets you mount C<file> (a filesystem image
+in a file) on a mount point. It is entirely equivalent to
+the command C<mount -o loop file mountpoint>.
+
+This function returns 0 on success or -1 on error.
+
=head2 guestfs_mount_options
int guestfs_mount_options (guestfs_h *handle,
diff --git a/haskell/Guestfs.hs b/haskell/Guestfs.hs
index 9eefda11..32e7aedd 100644
--- a/haskell/Guestfs.hs
+++ b/haskell/Guestfs.hs
@@ -120,7 +120,8 @@ module Guestfs (
wc_l,
wc_w,
wc_c,
- du
+ du,
+ mount_loop
) where
import Foreign
import Foreign.C
@@ -1335,3 +1336,15 @@ du h path = do
fail err
else return (fromIntegral r)
+foreign import ccall unsafe "guestfs_mount_loop" c_mount_loop
+ :: GuestfsP -> CString -> CString -> IO (CInt)
+
+mount_loop :: GuestfsH -> String -> String -> IO ()
+mount_loop h file mountpoint = do
+ r <- withCString file $ \file -> withCString mountpoint $ \mountpoint -> withForeignPtr h (\p -> c_mount_loop p file mountpoint)
+ if (r == -1)
+ then do
+ err <- last_error h
+ fail err
+ else return ()
+
diff --git a/images/Makefile.am b/images/Makefile.am
index 71d63a83..f2dd31ba 100644
--- a/images/Makefile.am
+++ b/images/Makefile.am
@@ -26,7 +26,8 @@ noinst_DATA = test.sqsh
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 $@
@@ -60,3 +61,8 @@ test.sqsh: $(squash_files)
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 $@
diff --git a/inspector/virt-inspector.pl b/inspector/virt-inspector.pl
index 553c36ad..66b1553e 100755
--- a/inspector/virt-inspector.pl
+++ b/inspector/virt-inspector.pl
@@ -734,9 +734,6 @@ sub find_filesystem
# 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};
@@ -751,7 +748,7 @@ if ($output !~ /.*fish$/) {
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 ();
@@ -914,42 +911,22 @@ sub check_for_initrd
{
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"
}
}
}
diff --git a/java/com/redhat/et/libguestfs/GuestFS.java b/java/com/redhat/et/libguestfs/GuestFS.java
index 6adeb211..f2901497 100644
--- a/java/com/redhat/et/libguestfs/GuestFS.java
+++ b/java/com/redhat/et/libguestfs/GuestFS.java
@@ -3794,4 +3794,49 @@ public HashMap<String,String> test0rhashtableerr ()
private native long _du (long g, String path)
throws LibGuestFSException;
+ /**
+ * list files in an initrd
+ * <p>
+ * This command lists out files contained in an initrd.
+ * <p>
+ * The files are listed without any initial "/" character.
+ * The files are listed in the order they appear (not
+ * necessarily alphabetical). Directory names are listed as
+ * separate items.
+ * <p>
+ * Old Linux kernels (2.4 and earlier) used a compressed
+ * ext2 filesystem as initrd. We *only* support the newer
+ * initramfs format (compressed cpio files).
+ * <p>
+ * @throws LibGuestFSException
+ */
+ public String[] initrd_list (String path)
+ throws LibGuestFSException
+ {
+ if (g == 0)
+ throw new LibGuestFSException ("initrd_list: handle is closed");
+ return _initrd_list (g, path);
+ }
+ private native String[] _initrd_list (long g, String path)
+ throws LibGuestFSException;
+
+ /**
+ * mount a file using the loop device
+ * <p>
+ * This command lets you mount "file" (a filesystem image
+ * in a file) on a mount point. It is entirely equivalent
+ * to the command "mount -o loop file mountpoint".
+ * <p>
+ * @throws LibGuestFSException
+ */
+ public void mount_loop (String file, String mountpoint)
+ throws LibGuestFSException
+ {
+ if (g == 0)
+ throw new LibGuestFSException ("mount_loop: handle is closed");
+ _mount_loop (g, file, mountpoint);
+ }
+ private native void _mount_loop (long g, String file, String mountpoint)
+ throws LibGuestFSException;
+
}
diff --git a/java/com_redhat_et_libguestfs_GuestFS.c b/java/com_redhat_et_libguestfs_GuestFS.c
index 3b91b40c..a58b489a 100644
--- a/java/com_redhat_et_libguestfs_GuestFS.c
+++ b/java/com_redhat_et_libguestfs_GuestFS.c
@@ -4389,3 +4389,56 @@ Java_com_redhat_et_libguestfs_GuestFS__1du
return (jlong) r;
}
+JNIEXPORT jobjectArray JNICALL
+Java_com_redhat_et_libguestfs_GuestFS__1initrd_1list
+ (JNIEnv *env, jobject obj, jlong jg, jstring jpath)
+{
+ guestfs_h *g = (guestfs_h *) (long) jg;
+ jobjectArray jr;
+ int r_len;
+ jclass cl;
+ jstring jstr;
+ char **r;
+ const char *path;
+ int i;
+
+ path = (*env)->GetStringUTFChars (env, jpath, NULL);
+ r = guestfs_initrd_list (g, path);
+ (*env)->ReleaseStringUTFChars (env, jpath, path);
+ if (r == NULL) {
+ throw_exception (env, guestfs_last_error (g));
+ return NULL;
+ }
+ for (r_len = 0; r[r_len] != NULL; ++r_len) ;
+ cl = (*env)->FindClass (env, "java/lang/String");
+ jstr = (*env)->NewStringUTF (env, "");
+ jr = (*env)->NewObjectArray (env, r_len, cl, jstr);
+ for (i = 0; i < r_len; ++i) {
+ jstr = (*env)->NewStringUTF (env, r[i]);
+ (*env)->SetObjectArrayElement (env, jr, i, jstr);
+ free (r[i]);
+ }
+ free (r);
+ return jr;
+}
+
+JNIEXPORT void JNICALL
+Java_com_redhat_et_libguestfs_GuestFS__1mount_1loop
+ (JNIEnv *env, jobject obj, jlong jg, jstring jfile, jstring jmountpoint)
+{
+ guestfs_h *g = (guestfs_h *) (long) jg;
+ int r;
+ const char *file;
+ const char *mountpoint;
+
+ file = (*env)->GetStringUTFChars (env, jfile, NULL);
+ mountpoint = (*env)->GetStringUTFChars (env, jmountpoint, NULL);
+ r = guestfs_mount_loop (g, file, mountpoint);
+ (*env)->ReleaseStringUTFChars (env, jfile, file);
+ (*env)->ReleaseStringUTFChars (env, jmountpoint, mountpoint);
+ if (r == -1) {
+ throw_exception (env, guestfs_last_error (g));
+ return ;
+ }
+}
+
diff --git a/ocaml/guestfs.ml b/ocaml/guestfs.ml
index 90f3ca8d..d9b652b7 100644
--- a/ocaml/guestfs.ml
+++ b/ocaml/guestfs.ml
@@ -294,3 +294,5 @@ external tail_n : t -> int -> string -> string array = "ocaml_guestfs_tail_n"
external df : t -> string = "ocaml_guestfs_df"
external df_h : t -> string = "ocaml_guestfs_df_h"
external du : t -> string -> int64 = "ocaml_guestfs_du"
+external initrd_list : t -> string -> string array = "ocaml_guestfs_initrd_list"
+external mount_loop : t -> string -> string -> unit = "ocaml_guestfs_mount_loop"
diff --git a/ocaml/guestfs.mli b/ocaml/guestfs.mli
index 39df5045..612d0022 100644
--- a/ocaml/guestfs.mli
+++ b/ocaml/guestfs.mli
@@ -661,3 +661,9 @@ val df_h : t -> string
val du : t -> string -> int64
(** estimate file space usage *)
+val initrd_list : t -> string -> string array
+(** list files in an initrd *)
+
+val mount_loop : t -> string -> string -> unit
+(** mount a file using the loop device *)
+
diff --git a/ocaml/guestfs_c_actions.c b/ocaml/guestfs_c_actions.c
index a5e18940..8b018f6e 100644
--- a/ocaml/guestfs_c_actions.c
+++ b/ocaml/guestfs_c_actions.c
@@ -4611,3 +4611,53 @@ ocaml_guestfs_du (value gv, value pathv)
CAMLreturn (rv);
}
+CAMLprim value
+ocaml_guestfs_initrd_list (value gv, value pathv)
+{
+ CAMLparam2 (gv, pathv);
+ CAMLlocal1 (rv);
+
+ guestfs_h *g = Guestfs_val (gv);
+ if (g == NULL)
+ caml_failwith ("initrd_list: used handle after closing it");
+
+ const char *path = String_val (pathv);
+ int i;
+ char **r;
+
+ caml_enter_blocking_section ();
+ r = guestfs_initrd_list (g, path);
+ caml_leave_blocking_section ();
+ if (r == NULL)
+ ocaml_guestfs_raise_error (g, "initrd_list");
+
+ rv = caml_copy_string_array ((const char **) r);
+ for (i = 0; r[i] != NULL; ++i) free (r[i]);
+ free (r);
+ CAMLreturn (rv);
+}
+
+CAMLprim value
+ocaml_guestfs_mount_loop (value gv, value filev, value mountpointv)
+{
+ CAMLparam3 (gv, filev, mountpointv);
+ CAMLlocal1 (rv);
+
+ guestfs_h *g = Guestfs_val (gv);
+ if (g == NULL)
+ caml_failwith ("mount_loop: used handle after closing it");
+
+ const char *file = String_val (filev);
+ const char *mountpoint = String_val (mountpointv);
+ int r;
+
+ caml_enter_blocking_section ();
+ r = guestfs_mount_loop (g, file, mountpoint);
+ caml_leave_blocking_section ();
+ if (r == -1)
+ ocaml_guestfs_raise_error (g, "mount_loop");
+
+ rv = Val_unit;
+ CAMLreturn (rv);
+}
+
diff --git a/perl/Guestfs.xs b/perl/Guestfs.xs
index d6ef053d..f19ea1a1 100644
--- a/perl/Guestfs.xs
+++ b/perl/Guestfs.xs
@@ -2812,3 +2812,34 @@ PREINIT:
OUTPUT:
RETVAL
+void
+initrd_list (g, path)
+ guestfs_h *g;
+ char *path;
+PREINIT:
+ char **filenames;
+ int i, n;
+ PPCODE:
+ filenames = guestfs_initrd_list (g, path);
+ if (filenames == NULL)
+ croak ("initrd_list: %s", guestfs_last_error (g));
+ for (n = 0; filenames[n] != NULL; ++n) /**/;
+ EXTEND (SP, n);
+ for (i = 0; i < n; ++i) {
+ PUSHs (sv_2mortal (newSVpv (filenames[i], 0)));
+ free (filenames[i]);
+ }
+ free (filenames);
+
+void
+mount_loop (g, file, mountpoint)
+ guestfs_h *g;
+ char *file;
+ char *mountpoint;
+PREINIT:
+ int r;
+ PPCODE:
+ r = guestfs_mount_loop (g, file, mountpoint);
+ if (r == -1)
+ croak ("mount_loop: %s", guestfs_last_error (g));
+
diff --git a/perl/lib/Sys/Guestfs.pm b/perl/lib/Sys/Guestfs.pm
index 655624a9..f0eb6a0f 100644
--- a/perl/lib/Sys/Guestfs.pm
+++ b/perl/lib/Sys/Guestfs.pm
@@ -755,6 +755,18 @@ Because of the message protocol, there is a transfer limit
of somewhere between 2MB and 4MB. To transfer large files you should use
FTP.
+=item @filenames = $h->initrd_list ($path);
+
+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).
+
=item $busy = $h->is_busy ();
This returns true iff this handle is busy processing a command
@@ -950,6 +962,12 @@ on the underlying device.
The filesystem options C<sync> and C<noatime> are set with this
call, in order to improve reliability.
+=item $h->mount_loop ($file, $mountpoint);
+
+This command lets you mount C<file> (a filesystem image
+in a file) on a mount point. It is entirely equivalent to
+the command C<mount -o loop file mountpoint>.
+
=item $h->mount_options ($options, $device, $mountpoint);
This is the same as the C<$h-E<gt>mount> command, but it
diff --git a/python/guestfs-py.c b/python/guestfs-py.c
index ac1283be..6a81349b 100644
--- a/python/guestfs-py.c
+++ b/python/guestfs-py.c
@@ -4877,6 +4877,57 @@ py_guestfs_du (PyObject *self, PyObject *args)
return py_r;
}
+static PyObject *
+py_guestfs_initrd_list (PyObject *self, PyObject *args)
+{
+ PyObject *py_g;
+ guestfs_h *g;
+ PyObject *py_r;
+ char **r;
+ const char *path;
+
+ if (!PyArg_ParseTuple (args, (char *) "Os:guestfs_initrd_list",
+ &py_g, &path))
+ return NULL;
+ g = get_handle (py_g);
+
+ r = guestfs_initrd_list (g, path);
+ if (r == NULL) {
+ PyErr_SetString (PyExc_RuntimeError, guestfs_last_error (g));
+ return NULL;
+ }
+
+ py_r = put_string_list (r);
+ free_strings (r);
+ return py_r;
+}
+
+static PyObject *
+py_guestfs_mount_loop (PyObject *self, PyObject *args)
+{
+ PyObject *py_g;
+ guestfs_h *g;
+ PyObject *py_r;
+ int r;
+ const char *file;
+ const char *mountpoint;
+
+ if (!PyArg_ParseTuple (args, (char *) "Oss:guestfs_mount_loop",
+ &py_g, &file, &mountpoint))
+ return NULL;
+ g = get_handle (py_g);
+
+ r = guestfs_mount_loop (g, file, mountpoint);
+ if (r == -1) {
+ PyErr_SetString (PyExc_RuntimeError, guestfs_last_error (g));
+ return NULL;
+ }
+
+ Py_INCREF (Py_None);
+ py_r = Py_None;
+ return py_r;
+}
+
static PyMethodDef methods[] = {
{ (char *) "create", py_guestfs_create, METH_VARARGS, NULL },
{ (char *) "close", py_guestfs_close, METH_VARARGS, NULL },
@@ -5059,6 +5110,8 @@ static PyMethodDef methods[] = {
{ (char *) "df", py_guestfs_df, METH_VARARGS, NULL },
{ (char *) "df_h", py_guestfs_df_h, METH_VARARGS, NULL },
{ (char *) "du", py_guestfs_du, METH_VARARGS, NULL },
+ { (char *) "initrd_list", py_guestfs_initrd_list, METH_VARARGS, NULL },
+ { (char *) "mount_loop", py_guestfs_mount_loop, METH_VARARGS, NULL },
{ NULL, NULL, 0, NULL }
};
diff --git a/python/guestfs.py b/python/guestfs.py
index e62a5271..46b02a48 100644
--- a/python/guestfs.py
+++ b/python/guestfs.py
@@ -1840,3 +1840,26 @@ class GuestFS:
"""
return libguestfsmod.du (self._o, path)
+ def initrd_list (self, path):
+ u"""This command lists out files contained in an initrd.
+
+ The files are listed without any initial "/" 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 *only* support the newer
+ initramfs format (compressed cpio files).
+
+ This function returns a list of strings.
+ """
+ return libguestfsmod.initrd_list (self._o, path)
+
+ def mount_loop (self, file, mountpoint):
+ u"""This command lets you mount "file" (a filesystem image
+ in a file) on a mount point. It is entirely equivalent
+ to the command "mount -o loop file mountpoint".
+ """
+ return libguestfsmod.mount_loop (self._o, file, mountpoint)
+
diff --git a/ruby/ext/guestfs/_guestfs.c b/ruby/ext/guestfs/_guestfs.c
index 679c5b0f..40654f9b 100644
--- a/ruby/ext/guestfs/_guestfs.c
+++ b/ruby/ext/guestfs/_guestfs.c
@@ -4581,6 +4581,63 @@ static VALUE ruby_guestfs_du (VALUE gv, VALUE pathv)
return ULL2NUM (r);
}
+static VALUE ruby_guestfs_initrd_list (VALUE gv, VALUE pathv)
+{
+ guestfs_h *g;
+ Data_Get_Struct (gv, guestfs_h, g);
+ if (!g)
+ rb_raise (rb_eArgError, "%s: used handle after closing it", "initrd_list");
+
+ Check_Type (pathv, T_STRING);
+ const char *path = StringValueCStr (pathv);
+ if (!path)
+ rb_raise (rb_eTypeError, "expected string for parameter %s of %s",
+ "path", "initrd_list");
+
+ char **r;
+
+ r = guestfs_initrd_list (g, path);
+ if (r == NULL)
+ rb_raise (e_Error, "%s", guestfs_last_error (g));
+
+ int i, len = 0;
+ for (i = 0; r[i] != NULL; ++i) len++;
+ VALUE rv = rb_ary_new2 (len);
+ for (i = 0; r[i] != NULL; ++i) {
+ rb_ary_push (rv, rb_str_new2 (r[i]));
+ free (r[i]);
+ }
+ free (r);
+ return rv;
+}
+
+static VALUE ruby_guestfs_mount_loop (VALUE gv, VALUE filev, VALUE mountpointv)
+{
+ guestfs_h *g;
+ Data_Get_Struct (gv, guestfs_h, g);
+ if (!g)
+ rb_raise (rb_eArgError, "%s: used handle after closing it", "mount_loop");
+
+ Check_Type (filev, T_STRING);
+ const char *file = StringValueCStr (filev);
+ if (!file)
+ rb_raise (rb_eTypeError, "expected string for parameter %s of %s",
+ "file", "mount_loop");
+ Check_Type (mountpointv, T_STRING);
+ const char *mountpoint = StringValueCStr (mountpointv);
+ if (!mountpoint)
+ rb_raise (rb_eTypeError, "expected string for parameter %s of %s",
+ "mountpoint", "mount_loop");
+
+ int r;
+
+ r = guestfs_mount_loop (g, file, mountpoint);
+ if (r == -1)
+ rb_raise (e_Error, "%s", guestfs_last_error (g));
+
+ return Qnil;
+}
+
/* Initialize the module. */
void Init__guestfs ()
{
@@ -4949,4 +5006,8 @@ void Init__guestfs ()
ruby_guestfs_df_h, 0);
rb_define_method (c_guestfs, "du",
ruby_guestfs_du, 1);
+ rb_define_method (c_guestfs, "initrd_list",
+ ruby_guestfs_initrd_list, 1);
+ rb_define_method (c_guestfs, "mount_loop",
+ ruby_guestfs_mount_loop, 2);
}
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index c75acbe2..b0d73241 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-127
+129
diff --git a/src/generator.ml b/src/generator.ml
index 5885ff3f..27a75868 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -2599,6 +2599,30 @@ subdirectories (recursively).
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).");
+
+ ("mount_loop", (RErr, [String "file"; String "mountpoint"]), 129, [],
+ [],
+ "mount a file using the loop device",
+ "\
+This command lets you mount C<file> (a filesystem image
+in a file) on a mount point. It is entirely equivalent to
+the command C<mount -o loop file mountpoint>.");
+
]
let all_functions = non_daemon_functions @ daemon_functions
diff --git a/src/guestfs-actions.c b/src/guestfs-actions.c
index b34c8017..94a08629 100644
--- a/src/guestfs-actions.c
+++ b/src/guestfs-actions.c
@@ -11649,3 +11649,189 @@ int64_t guestfs_du (guestfs_h *g,
return ctx.ret.sizekb;
}
+struct initrd_list_ctx {
+ /* This flag is set by the callbacks, so we know we've done
+ * the callbacks as expected, and in the right sequence.
+ * 0 = not called, 1 = reply_cb called.
+ */
+ int cb_sequence;
+ struct guestfs_message_header hdr;
+ struct guestfs_message_error err;
+ struct guestfs_initrd_list_ret ret;
+};
+
+static void initrd_list_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+ guestfs_main_loop *ml = guestfs_get_main_loop (g);
+ struct initrd_list_ctx *ctx = (struct initrd_list_ctx *) data;
+
+ /* This should definitely not happen. */
+ if (ctx->cb_sequence != 0) {
+ ctx->cb_sequence = 9999;
+ error (g, "%s: internal error: reply callback called twice", "guestfs_initrd_list");
+ return;
+ }
+
+ ml->main_loop_quit (ml, g);
+
+ if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+ error (g, "%s: failed to parse reply header", "guestfs_initrd_list");
+ return;
+ }
+ if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+ if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+ error (g, "%s: failed to parse reply error", "guestfs_initrd_list");
+ return;
+ }
+ goto done;
+ }
+ if (!xdr_guestfs_initrd_list_ret (xdr, &ctx->ret)) {
+ error (g, "%s: failed to parse reply", "guestfs_initrd_list");
+ return;
+ }
+ done:
+ ctx->cb_sequence = 1;
+}
+
+char **guestfs_initrd_list (guestfs_h *g,
+ const char *path)
+{
+ struct guestfs_initrd_list_args args;
+ struct initrd_list_ctx ctx;
+ guestfs_main_loop *ml = guestfs_get_main_loop (g);
+ int serial;
+
+ if (check_state (g, "guestfs_initrd_list") == -1) return NULL;
+ guestfs_set_busy (g);
+
+ memset (&ctx, 0, sizeof ctx);
+
+ args.path = (char *) path;
+ serial = guestfs__send_sync (g, GUESTFS_PROC_INITRD_LIST,
+ (xdrproc_t) xdr_guestfs_initrd_list_args, (char *) &args);
+ if (serial == -1) {
+ guestfs_end_busy (g);
+ return NULL;
+ }
+
+ guestfs__switch_to_receiving (g);
+ ctx.cb_sequence = 0;
+ guestfs_set_reply_callback (g, initrd_list_reply_cb, &ctx);
+ (void) ml->main_loop_run (ml, g);
+ guestfs_set_reply_callback (g, NULL, NULL);
+ if (ctx.cb_sequence != 1) {
+ error (g, "%s reply failed, see earlier error messages", "guestfs_initrd_list");
+ guestfs_end_busy (g);
+ return NULL;
+ }
+
+ if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_INITRD_LIST, serial) == -1) {
+ guestfs_end_busy (g);
+ return NULL;
+ }
+
+ if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+ error (g, "%s", ctx.err.error_message);
+ free (ctx.err.error_message);
+ guestfs_end_busy (g);
+ return NULL;
+ }
+
+ guestfs_end_busy (g);
+ /* caller will free this, but we need to add a NULL entry */
+ ctx.ret.filenames.filenames_val =
+ safe_realloc (g, ctx.ret.filenames.filenames_val,
+ sizeof (char *) * (ctx.ret.filenames.filenames_len + 1));
+ ctx.ret.filenames.filenames_val[ctx.ret.filenames.filenames_len] = NULL;
+ return ctx.ret.filenames.filenames_val;
+}
+
+struct mount_loop_ctx {
+ /* This flag is set by the callbacks, so we know we've done
+ * the callbacks as expected, and in the right sequence.
+ * 0 = not called, 1 = reply_cb called.
+ */
+ int cb_sequence;
+ struct guestfs_message_header hdr;
+ struct guestfs_message_error err;
+};
+
+static void mount_loop_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+ guestfs_main_loop *ml = guestfs_get_main_loop (g);
+ struct mount_loop_ctx *ctx = (struct mount_loop_ctx *) data;
+
+ /* This should definitely not happen. */
+ if (ctx->cb_sequence != 0) {
+ ctx->cb_sequence = 9999;
+ error (g, "%s: internal error: reply callback called twice", "guestfs_mount_loop");
+ return;
+ }
+
+ ml->main_loop_quit (ml, g);
+
+ if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+ error (g, "%s: failed to parse reply header", "guestfs_mount_loop");
+ return;
+ }
+ if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+ if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+ error (g, "%s: failed to parse reply error", "guestfs_mount_loop");
+ return;
+ }
+ goto done;
+ }
+ done:
+ ctx->cb_sequence = 1;
+}
+
+int guestfs_mount_loop (guestfs_h *g,
+ const char *file,
+ const char *mountpoint)
+{
+ struct guestfs_mount_loop_args args;
+ struct mount_loop_ctx ctx;
+ guestfs_main_loop *ml = guestfs_get_main_loop (g);
+ int serial;
+
+ if (check_state (g, "guestfs_mount_loop") == -1) return -1;
+ guestfs_set_busy (g);
+
+ memset (&ctx, 0, sizeof ctx);
+
+ args.file = (char *) file;
+ args.mountpoint = (char *) mountpoint;
+ serial = guestfs__send_sync (g, GUESTFS_PROC_MOUNT_LOOP,
+ (xdrproc_t) xdr_guestfs_mount_loop_args, (char *) &args);
+ if (serial == -1) {
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ guestfs__switch_to_receiving (g);
+ ctx.cb_sequence = 0;
+ guestfs_set_reply_callback (g, mount_loop_reply_cb, &ctx);
+ (void) ml->main_loop_run (ml, g);
+ guestfs_set_reply_callback (g, NULL, NULL);
+ if (ctx.cb_sequence != 1) {
+ error (g, "%s reply failed, see earlier error messages", "guestfs_mount_loop");
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MOUNT_LOOP, serial) == -1) {
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+ error (g, "%s", ctx.err.error_message);
+ free (ctx.err.error_message);
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ guestfs_end_busy (g);
+ return 0;
+}
+
diff --git a/src/guestfs-actions.h b/src/guestfs-actions.h
index 3c983325..c0002662 100644
--- a/src/guestfs-actions.h
+++ b/src/guestfs-actions.h
@@ -198,3 +198,5 @@ extern char **guestfs_tail_n (guestfs_h *handle, int nrlines, const char *path);
extern char *guestfs_df (guestfs_h *handle);
extern char *guestfs_df_h (guestfs_h *handle);
extern int64_t guestfs_du (guestfs_h *handle, const char *path);
+extern char **guestfs_initrd_list (guestfs_h *handle, const char *path);
+extern int guestfs_mount_loop (guestfs_h *handle, const char *file, const char *mountpoint);
diff --git a/src/guestfs.c b/src/guestfs.c
index fdf5cd36..016d8035 100644
--- a/src/guestfs.c
+++ b/src/guestfs.c
@@ -1677,7 +1677,7 @@ static void
sock_write_event (struct guestfs_main_loop *ml, guestfs_h *g, void *data,
int watch, int fd, int events)
{
- int n;
+ int n, err;
if (g->verbose)
fprintf (stderr,
@@ -1701,8 +1701,11 @@ sock_write_event (struct guestfs_main_loop *ml, guestfs_h *g, void *data,
n = write (g->sock, g->msg_out + g->msg_out_pos,
g->msg_out_size - g->msg_out_pos);
if (n == -1) {
- if (errno != EAGAIN)
+ err = errno;
+ if (err != EAGAIN)
perrorf (g, "write");
+ if (err == EPIPE) /* Disconnected from guest (RHBZ#508713). */
+ child_cleanup (g);
return;
}
diff --git a/src/guestfs_protocol.c b/src/guestfs_protocol.c
index 050d9282..9b12986c 100644
--- a/src/guestfs_protocol.c
+++ b/src/guestfs_protocol.c
@@ -2171,6 +2171,39 @@ xdr_guestfs_du_ret (XDR *xdrs, guestfs_du_ret *objp)
}
bool_t
+xdr_guestfs_initrd_list_args (XDR *xdrs, guestfs_initrd_list_args *objp)
+{
+ register int32_t *buf;
+
+ if (!xdr_string (xdrs, &objp->path, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_guestfs_initrd_list_ret (XDR *xdrs, guestfs_initrd_list_ret *objp)
+{
+ register int32_t *buf;
+
+ if (!xdr_array (xdrs, (char **)&objp->filenames.filenames_val, (u_int *) &objp->filenames.filenames_len, ~0,
+ sizeof (str), (xdrproc_t) xdr_str))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_guestfs_mount_loop_args (XDR *xdrs, guestfs_mount_loop_args *objp)
+{
+ register int32_t *buf;
+
+ if (!xdr_string (xdrs, &objp->file, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->mountpoint, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
xdr_guestfs_procedure (XDR *xdrs, guestfs_procedure *objp)
{
register int32_t *buf;
diff --git a/src/guestfs_protocol.h b/src/guestfs_protocol.h
index c8231a0d..d127b884 100644
--- a/src/guestfs_protocol.h
+++ b/src/guestfs_protocol.h
@@ -1111,6 +1111,25 @@ struct guestfs_du_ret {
};
typedef struct guestfs_du_ret guestfs_du_ret;
+struct guestfs_initrd_list_args {
+ char *path;
+};
+typedef struct guestfs_initrd_list_args guestfs_initrd_list_args;
+
+struct guestfs_initrd_list_ret {
+ struct {
+ u_int filenames_len;
+ str *filenames_val;
+ } filenames;
+};
+typedef struct guestfs_initrd_list_ret guestfs_initrd_list_ret;
+
+struct guestfs_mount_loop_args {
+ char *file;
+ char *mountpoint;
+};
+typedef struct guestfs_mount_loop_args guestfs_mount_loop_args;
+
enum guestfs_procedure {
GUESTFS_PROC_MOUNT = 1,
GUESTFS_PROC_SYNC = 2,
@@ -1239,7 +1258,9 @@ enum guestfs_procedure {
GUESTFS_PROC_DF = 125,
GUESTFS_PROC_DF_H = 126,
GUESTFS_PROC_DU = 127,
- GUESTFS_PROC_NR_PROCS = 127 + 1,
+ GUESTFS_PROC_INITRD_LIST = 128,
+ GUESTFS_PROC_MOUNT_LOOP = 129,
+ GUESTFS_PROC_NR_PROCS = 129 + 1,
};
typedef enum guestfs_procedure guestfs_procedure;
#define GUESTFS_MESSAGE_MAX 4194304
@@ -1469,6 +1490,9 @@ extern bool_t xdr_guestfs_df_ret (XDR *, guestfs_df_ret*);
extern bool_t xdr_guestfs_df_h_ret (XDR *, guestfs_df_h_ret*);
extern bool_t xdr_guestfs_du_args (XDR *, guestfs_du_args*);
extern bool_t xdr_guestfs_du_ret (XDR *, guestfs_du_ret*);
+extern bool_t xdr_guestfs_initrd_list_args (XDR *, guestfs_initrd_list_args*);
+extern bool_t xdr_guestfs_initrd_list_ret (XDR *, guestfs_initrd_list_ret*);
+extern bool_t xdr_guestfs_mount_loop_args (XDR *, guestfs_mount_loop_args*);
extern bool_t xdr_guestfs_procedure (XDR *, guestfs_procedure*);
extern bool_t xdr_guestfs_message_direction (XDR *, guestfs_message_direction*);
extern bool_t xdr_guestfs_message_status (XDR *, guestfs_message_status*);
@@ -1657,6 +1681,9 @@ extern bool_t xdr_guestfs_df_ret ();
extern bool_t xdr_guestfs_df_h_ret ();
extern bool_t xdr_guestfs_du_args ();
extern bool_t xdr_guestfs_du_ret ();
+extern bool_t xdr_guestfs_initrd_list_args ();
+extern bool_t xdr_guestfs_initrd_list_ret ();
+extern bool_t xdr_guestfs_mount_loop_args ();
extern bool_t xdr_guestfs_procedure ();
extern bool_t xdr_guestfs_message_direction ();
extern bool_t xdr_guestfs_message_status ();
diff --git a/src/guestfs_protocol.x b/src/guestfs_protocol.x
index a895b6d5..fdc67c15 100644
--- a/src/guestfs_protocol.x
+++ b/src/guestfs_protocol.x
@@ -850,6 +850,19 @@ struct guestfs_du_ret {
hyper sizekb;
};
+struct guestfs_initrd_list_args {
+ string path<>;
+};
+
+struct guestfs_initrd_list_ret {
+ str filenames<>;
+};
+
+struct guestfs_mount_loop_args {
+ string file<>;
+ string mountpoint<>;
+};
+
enum guestfs_procedure {
GUESTFS_PROC_MOUNT = 1,
GUESTFS_PROC_SYNC = 2,
@@ -978,6 +991,8 @@ enum guestfs_procedure {
GUESTFS_PROC_DF = 125,
GUESTFS_PROC_DF_H = 126,
GUESTFS_PROC_DU = 127,
+ GUESTFS_PROC_INITRD_LIST = 128,
+ GUESTFS_PROC_MOUNT_LOOP = 129,
GUESTFS_PROC_NR_PROCS
};