Generated code for 'initrd-list'.
authorRichard W.M. Jones <rjones@redhat.com>
Mon, 29 Jun 2009 14:18:17 +0000 (15:18 +0100)
committerRichard W.M. Jones <rjones@redhat.com>
Mon, 29 Jun 2009 14:19:10 +0000 (15:19 +0100)
23 files changed:
capitests/tests.c
daemon/actions.h
daemon/stubs.c
fish/cmds.c
fish/completion.c
guestfish-actions.pod
guestfs-actions.pod
java/com/redhat/et/libguestfs/GuestFS.java
java/com_redhat_et_libguestfs_GuestFS.c
ocaml/guestfs.ml
ocaml/guestfs.mli
ocaml/guestfs_c_actions.c
perl/Guestfs.xs
perl/lib/Sys/Guestfs.pm
python/guestfs-py.c
python/guestfs.py
ruby/ext/guestfs/_guestfs.c
src/MAX_PROC_NR
src/guestfs-actions.c
src/guestfs-actions.h
src/guestfs_protocol.c
src/guestfs_protocol.h
src/guestfs_protocol.x

index 6e31c40..ba2e806 100644 (file)
@@ -155,6 +155,161 @@ static void no_test_warnings (void)
   fprintf (stderr, "warning: \"guestfs_df_h\" has no tests\n");
 }
 
   fprintf (stderr, "warning: \"guestfs_df_h\" 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)
 {
   const char *str;
 static int test_du_0_skip (void)
 {
   const char *str;
@@ -18608,9 +18763,15 @@ int main (int argc, char *argv[])
   /* Cancel previous alarm. */
   alarm (0);
 
   /* Cancel previous alarm. */
   alarm (0);
 
-  nr_tests = 165;
+  nr_tests = 166;
 
   test_num++;
 
   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");
   printf ("%3d/%3d test_du_0\n", test_num, nr_tests);
   if (test_du_0 () == -1) {
     printf ("test_du_0 FAILED\n");
index 7d87b67..8c3c5fe 100644 (file)
@@ -148,3 +148,4 @@ 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_df (void);
 extern char *do_df_h (void);
 extern int64_t do_du (char *path);
+extern char **do_initrd_list (char *path);
index 67e6ef5..294d9e6 100644 (file)
@@ -3205,6 +3205,34 @@ done:
   xdr_free ((xdrproc_t) xdr_guestfs_du_args, (char *) &args);
 }
 
   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);
+}
+
 void dispatch_incoming_message (XDR *xdr_in)
 {
   switch (proc_nr) {
 void dispatch_incoming_message (XDR *xdr_in)
 {
   switch (proc_nr) {
@@ -3589,6 +3617,9 @@ void dispatch_incoming_message (XDR *xdr_in)
     case GUESTFS_PROC_DU:
       du_stub (xdr_in);
       break;
     case GUESTFS_PROC_DU:
       du_stub (xdr_in);
       break;
+    case GUESTFS_PROC_INITRD_LIST:
+      initrd_list_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);
   }
     default:
       reply_with_error ("dispatch_incoming_message: unknown procedure number %d, set LIBGUESTFS_PATH to point to the matching libguestfs appliance directory", proc_nr);
   }
index c802f90..ed59804 100644 (file)
@@ -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", "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");
   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");
@@ -628,6 +629,9 @@ 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, "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
     display_builtin_command (cmd);
 }
 
     display_builtin_command (cmd);
 }
 
@@ -3082,6 +3086,23 @@ static int run_du (const char *cmd, int argc, char *argv[])
   return 0;
 }
 
   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;
+}
+
 int run_action (const char *cmd, int argc, char *argv[])
 {
   if (strcasecmp (cmd, "launch") == 0 || strcasecmp (cmd, "run") == 0)
 int run_action (const char *cmd, int argc, char *argv[])
 {
   if (strcasecmp (cmd, "launch") == 0 || strcasecmp (cmd, "run") == 0)
@@ -3528,6 +3549,9 @@ 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, "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
     {
       fprintf (stderr, "%s: unknown command\n", cmd);
       return -1;
     {
       fprintf (stderr, "%s: unknown command\n", cmd);
       return -1;
index 5254a37..ea75362 100644 (file)
@@ -194,6 +194,7 @@ static const char *const commands[] = {
   "df",
   "df-h",
   "du",
   "df",
   "df-h",
   "du",
+  "initrd-list",
   NULL
 };
 
   NULL
 };
 
index 9f625c7..2b4e99e 100644 (file)
@@ -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.
 
 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
 =head2 is-busy
 
  is-busy
index 039608d..18c3910 100644 (file)
@@ -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.
 
 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);
 =head2 guestfs_is_busy
 
  int guestfs_is_busy (guestfs_h *handle);
index 6adeb21..8ab3a4f 100644 (file)
@@ -3794,4 +3794,30 @@ public HashMap<String,String> test0rhashtableerr ()
   private native long _du (long g, String path)
     throws LibGuestFSException;
 
   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;
+
 }
 }
index 3b91b40..6d101a6 100644 (file)
@@ -4389,3 +4389,36 @@ Java_com_redhat_et_libguestfs_GuestFS__1du
   return (jlong) r;
 }
 
   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;
+}
+
index 90f3ca8..33c0276 100644 (file)
@@ -294,3 +294,4 @@ 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 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"
index 39df504..988d9de 100644 (file)
@@ -661,3 +661,6 @@ val df_h : t -> string
 val du : t -> string -> int64
 (** estimate file space usage *)
 
 val du : t -> string -> int64
 (** estimate file space usage *)
 
+val initrd_list : t -> string -> string array
+(** list files in an initrd *)
+
index a5e1894..6385e80 100644 (file)
@@ -4611,3 +4611,29 @@ ocaml_guestfs_du (value gv, value pathv)
   CAMLreturn (rv);
 }
 
   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);
+}
+
index d6ef053..c0846d8 100644 (file)
@@ -2812,3 +2812,22 @@ PREINIT:
  OUTPUT:
       RETVAL
 
  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);
+
index 655624a..144e127 100644 (file)
@@ -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.
 
 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
 =item $busy = $h->is_busy ();
 
 This returns true iff this handle is busy processing a command
index ac1283b..d2682f9 100644 (file)
@@ -4877,6 +4877,31 @@ py_guestfs_du (PyObject *self, PyObject *args)
   return py_r;
 }
 
   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 PyMethodDef methods[] = {
   { (char *) "create", py_guestfs_create, METH_VARARGS, NULL },
   { (char *) "close", py_guestfs_close, METH_VARARGS, NULL },
 static PyMethodDef methods[] = {
   { (char *) "create", py_guestfs_create, METH_VARARGS, NULL },
   { (char *) "close", py_guestfs_close, METH_VARARGS, NULL },
@@ -5059,6 +5084,7 @@ 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 *) "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 },
   { NULL, NULL, 0, NULL }
 };
 
   { NULL, NULL, 0, NULL }
 };
 
index e62a527..0f6fc3a 100644 (file)
@@ -1840,3 +1840,19 @@ class GuestFS:
         """
         return libguestfsmod.du (self._o, path)
 
         """
         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)
+
index 679c5b0..0d4c6dc 100644 (file)
@@ -4581,6 +4581,36 @@ static VALUE ruby_guestfs_du (VALUE gv, VALUE pathv)
   return ULL2NUM (r);
 }
 
   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;
+}
+
 /* Initialize the module. */
 void Init__guestfs ()
 {
 /* Initialize the module. */
 void Init__guestfs ()
 {
@@ -4949,4 +4979,6 @@ void Init__guestfs ()
         ruby_guestfs_df_h, 0);
   rb_define_method (c_guestfs, "du",
         ruby_guestfs_du, 1);
         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);
 }
 }
index c75acbe..a949a93 100644 (file)
@@ -1 +1 @@
-127
+128
index b34c801..93fdee6 100644 (file)
@@ -11649,3 +11649,100 @@ int64_t guestfs_du (guestfs_h *g,
   return ctx.ret.sizekb;
 }
 
   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;
+}
+
index 3c98332..43570bb 100644 (file)
@@ -198,3 +198,4 @@ 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_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);
index 050d928..6f135db 100644 (file)
@@ -2171,6 +2171,27 @@ xdr_guestfs_du_ret (XDR *xdrs, guestfs_du_ret *objp)
 }
 
 bool_t
 }
 
 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_procedure (XDR *xdrs, guestfs_procedure *objp)
 {
        register int32_t *buf;
 xdr_guestfs_procedure (XDR *xdrs, guestfs_procedure *objp)
 {
        register int32_t *buf;
index c8231a0..b850f9f 100644 (file)
@@ -1111,6 +1111,19 @@ struct guestfs_du_ret {
 };
 typedef struct guestfs_du_ret 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;
+
 enum guestfs_procedure {
        GUESTFS_PROC_MOUNT = 1,
        GUESTFS_PROC_SYNC = 2,
 enum guestfs_procedure {
        GUESTFS_PROC_MOUNT = 1,
        GUESTFS_PROC_SYNC = 2,
@@ -1239,7 +1252,8 @@ enum guestfs_procedure {
        GUESTFS_PROC_DF = 125,
        GUESTFS_PROC_DF_H = 126,
        GUESTFS_PROC_DU = 127,
        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_NR_PROCS = 128 + 1,
 };
 typedef enum guestfs_procedure guestfs_procedure;
 #define GUESTFS_MESSAGE_MAX 4194304
 };
 typedef enum guestfs_procedure guestfs_procedure;
 #define GUESTFS_MESSAGE_MAX 4194304
@@ -1469,6 +1483,8 @@ 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_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_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*);
 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 +1673,8 @@ 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_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_procedure ();
 extern bool_t xdr_guestfs_message_direction ();
 extern bool_t xdr_guestfs_message_status ();
 extern bool_t xdr_guestfs_procedure ();
 extern bool_t xdr_guestfs_message_direction ();
 extern bool_t xdr_guestfs_message_status ();
index a895b6d..42040ac 100644 (file)
@@ -850,6 +850,14 @@ struct guestfs_du_ret {
   hyper sizekb;
 };
 
   hyper sizekb;
 };
 
+struct guestfs_initrd_list_args {
+  string path<>;
+};
+
+struct guestfs_initrd_list_ret {
+  str filenames<>;
+};
+
 enum guestfs_procedure {
   GUESTFS_PROC_MOUNT = 1,
   GUESTFS_PROC_SYNC = 2,
 enum guestfs_procedure {
   GUESTFS_PROC_MOUNT = 1,
   GUESTFS_PROC_SYNC = 2,
@@ -978,6 +986,7 @@ enum guestfs_procedure {
   GUESTFS_PROC_DF = 125,
   GUESTFS_PROC_DF_H = 126,
   GUESTFS_PROC_DU = 127,
   GUESTFS_PROC_DF = 125,
   GUESTFS_PROC_DF_H = 126,
   GUESTFS_PROC_DU = 127,
+  GUESTFS_PROC_INITRD_LIST = 128,
   GUESTFS_PROC_NR_PROCS
 };
 
   GUESTFS_PROC_NR_PROCS
 };