[Libguestfs] CVE-2010-3851: Patch to the generated code

Richard W.M. Jones rjones at redhat.com
Fri Oct 22 15:50:27 UTC 2010


This is the patch to the generated code, which might make
patch 2/8 a little bit easier to follow.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://et.redhat.com/~rjones/virt-df/
-------------- next part --------------
diff -ur v1/capitests/tests.c v2/capitests/tests.c
--- v1/capitests/tests.c	2010-10-22 16:40:45.530961210 +0100
+++ v2/capitests/tests.c	2010-10-21 10:38:35.181927488 +0100
@@ -152,6 +152,7 @@
   fprintf (stderr, "warning: \"guestfs_set_network\" has no tests\n");
   fprintf (stderr, "warning: \"guestfs_get_network\" has no tests\n");
   fprintf (stderr, "warning: \"guestfs_list_filesystems\" has no tests\n");
+  fprintf (stderr, "warning: \"guestfs_add_drive_opts\" has no tests\n");
   fprintf (stderr, "warning: \"guestfs_ll\" has no tests\n");
   fprintf (stderr, "warning: \"guestfs_pvs_full\" has no tests\n");
   fprintf (stderr, "warning: \"guestfs_vgs_full\" has no tests\n");
diff -ur v1/csharp/Libguestfs.cs v2/csharp/Libguestfs.cs
--- v1/csharp/Libguestfs.cs	2010-10-22 16:40:46.650023964 +0100
+++ v2/csharp/Libguestfs.cs	2010-10-21 17:48:25.628139407 +0100
@@ -28,7 +28,8 @@
 // The second issue is that some calls are known to be incorrect and
 // can cause Mono to segfault.  Particularly: calls which pass or
 // return string[], or return any structure value.  This is because
-// we haven't worked out the correct way to do this from C#.
+// we haven't worked out the correct way to do this from C#.  Also
+// we don't handle functions that take optional arguments at all.
 //
 // The third issue is that when compiling you get a lot of warnings.
 // We are not sure whether the warnings are important or not.
@@ -255,6 +256,20 @@
     }
 
     [DllImport ("libguestfs.so.0")]
+    static extern int guestfs_add_drive_opts (IntPtr h, [In] string filename);
+
+    /// <summary>
+    /// add an image to examine or modify
+    /// </summary>
+    public void add_drive_opts (string filename)
+    {
+      int r;
+      r = guestfs_add_drive_opts (_handle, filename);
+      if (r == -1)
+        throw new Error (guestfs_last_error (_handle));
+    }
+
+    [DllImport ("libguestfs.so.0")]
     static extern int guestfs_add_drive_ro (IntPtr h, [In] string filename);
 
     /// <summary>
diff -ur v1/fish/cmds.c v2/fish/cmds.c
--- v1/fish/cmds.c	2010-10-22 16:40:45.664968720 +0100
+++ v2/fish/cmds.c	2010-10-22 16:35:39.304790165 +0100
@@ -42,6 +42,7 @@
   list_builtin_commands ();
   printf ("%-20s %s\n", "add-cdrom", _("add a CD-ROM disk image to examine"));
   printf ("%-20s %s\n", "add-drive", _("add an image to examine or modify"));
+  printf ("%-20s %s\n", "add-drive-opts", _("add an image to examine or modify"));
   printf ("%-20s %s\n", "add-drive-ro", _("add a drive in snapshot mode (read-only)"));
   printf ("%-20s %s\n", "add-drive-ro-with-if", _("add a drive read-only specifying the QEMU block emulation to use"));
   printf ("%-20s %s\n", "add-drive-with-if", _("add a drive specifying the QEMU block emulation to use"));
@@ -463,18 +464,18 @@
     return 0;
   }
   else
-  if (STRCASEEQ (cmd, "add_drive") || STRCASEEQ (cmd, "add-drive") || STRCASEEQ (cmd, "add")) {
-    pod2text ("add-drive", _("add an image to examine or modify"), "=head1 SYNOPSIS\n\n add-drive filename\n\n=head1 DESCRIPTION\n\nThis function adds a virtual machine disk image C<filename> to the\nguest.  The first time you call this function, the disk appears as IDE\ndisk 0 (C</dev/sda>) in the guest, the second time as C</dev/sdb>, and\nso on.\n\nYou don't necessarily need to be root when using libguestfs.  However\nyou obviously do need sufficient permissions to access the filename\nfor whatever operations you want to perform (ie. read access if you\njust want to read the image or write access if you want to modify the\nimage).\n\nThis is equivalent to the qemu parameter\nC<-drive file=filename,cache=off,if=...>.\n\nC<cache=off> is omitted in cases where it is not supported by\nthe underlying filesystem.\n\nC<if=...> is set at compile time by the configuration option\nC<./configure --with-drive-if=...>.  In the rare case where you\nmight need to change this at run time, use C<add_drive_with_if>\nor C<add_drive_ro_with_if>.\n\nNote that this call checks for the existence of C<filename>.  This\nstops you from specifying other types of drive which are supported\nby qemu such as C<nbd:> and C<http:> URLs.  To specify those, use\nthe general C<config> call instead.\n\nYou can use 'add' as an alias for this command.");
+  if (STRCASEEQ (cmd, "add_drive") || STRCASEEQ (cmd, "add-drive")) {
+    pod2text ("add-drive", _("add an image to examine or modify"), "=head1 SYNOPSIS\n\n add-drive filename\n\n=head1 DESCRIPTION\n\nThis function is the equivalent of calling C<add_drive_opts>\nwith no optional parameters, so the disk is added writable, with\nthe format being detected automatically.\n\nAutomatic detection of the format opens you up to a potential\nsecurity hole when dealing with untrusted raw-format images.\nSee CVE-2010-3851 and RHBZ#642934.  Specifying the format closes\nthis security hole.  Therefore you should think about replacing\ncalls to this function with calls to C<add_drive_opts>,\nand specifying the format.");
     return 0;
   }
   else
-  if (STRCASEEQ (cmd, "add_cdrom") || STRCASEEQ (cmd, "add-cdrom") || STRCASEEQ (cmd, "cdrom")) {
-    pod2text ("add-cdrom", _("add a CD-ROM disk image to examine"), "=head1 SYNOPSIS\n\n add-cdrom filename\n\n=head1 DESCRIPTION\n\nThis function adds a virtual CD-ROM disk image to the guest.\n\nThis is equivalent to the qemu parameter C<-cdrom filename>.\n\nNotes:\n\n=over 4\n\n=item *\n\nThis call checks for the existence of C<filename>.  This\nstops you from specifying other types of drive which are supported\nby qemu such as C<nbd:> and C<http:> URLs.  To specify those, use\nthe general C<config> call instead.\n\n=item *\n\nIf you just want to add an ISO file (often you use this as an\nefficient way to transfer large files into the guest), then you\nshould probably use C<add_drive_ro> instead.\n\n=back\n\nYou can use 'cdrom' as an alias for this command.");
+  if (STRCASEEQ (cmd, "add_cdrom") || STRCASEEQ (cmd, "add-cdrom")) {
+    pod2text ("add-cdrom", _("add a CD-ROM disk image to examine"), "=head1 SYNOPSIS\n\n add-cdrom filename\n\n=head1 DESCRIPTION\n\nThis function adds a virtual CD-ROM disk image to the guest.\n\nThis is equivalent to the qemu parameter C<-cdrom filename>.\n\nNotes:\n\n=over 4\n\n=item *\n\nThis call checks for the existence of C<filename>.  This\nstops you from specifying other types of drive which are supported\nby qemu such as C<nbd:> and C<http:> URLs.  To specify those, use\nthe general C<config> call instead.\n\n=item *\n\nIf you just want to add an ISO file (often you use this as an\nefficient way to transfer large files into the guest), then you\nshould probably use C<add_drive_ro> instead.\n\n=back\n\nThis function is deprecated.\nIn new code, use the C<add_drive_opts> call instead.\n\nDeprecated functions will not be removed from the API, but the\nfact that they are deprecated indicates that there are problems\nwith correct use of these functions.");
     return 0;
   }
   else
   if (STRCASEEQ (cmd, "add_drive_ro") || STRCASEEQ (cmd, "add-drive-ro") || STRCASEEQ (cmd, "add-ro")) {
-    pod2text ("add-drive-ro", _("add a drive in snapshot mode (read-only)"), "=head1 SYNOPSIS\n\n add-drive-ro filename\n\n=head1 DESCRIPTION\n\nThis adds a drive in snapshot mode, making it effectively\nread-only.\n\nNote that writes to the device are allowed, and will be seen for\nthe duration of the guestfs handle, but they are written\nto a temporary file which is discarded as soon as the guestfs\nhandle is closed.  We don't currently have any method to enable\nchanges to be committed, although qemu can support this.\n\nThis is equivalent to the qemu parameter\nC<-drive file=filename,snapshot=on,if=...>.\n\nC<if=...> is set at compile time by the configuration option\nC<./configure --with-drive-if=...>.  In the rare case where you\nmight need to change this at run time, use C<add_drive_with_if>\nor C<add_drive_ro_with_if>.\n\nNote that this call checks for the existence of C<filename>.  This\nstops you from specifying other types of drive which are supported\nby qemu such as C<nbd:> and C<http:> URLs.  To specify those, use\nthe general C<config> call instead.\n\nYou can use 'add-ro' as an alias for this command.");
+    pod2text ("add-drive-ro", _("add a drive in snapshot mode (read-only)"), "=head1 SYNOPSIS\n\n add-drive-ro filename\n\n=head1 DESCRIPTION\n\nThis function is the equivalent of calling C<add_drive_opts>\nwith the optional parameter C<GUESTFS_ADD_DRIVE_OPTS_READONLY> set to 1,\nso the disk is added read-only, with the format being detected\nautomatically.\n\nYou can use 'add-ro' as an alias for this command.");
     return 0;
   }
   else
@@ -619,12 +620,12 @@
   }
   else
   if (STRCASEEQ (cmd, "add_drive_with_if") || STRCASEEQ (cmd, "add-drive-with-if")) {
-    pod2text ("add-drive-with-if", _("add a drive specifying the QEMU block emulation to use"), "=head1 SYNOPSIS\n\n add-drive-with-if filename iface\n\n=head1 DESCRIPTION\n\nThis is the same as C<add_drive> but it allows you\nto specify the QEMU interface emulation to use at run time.");
+    pod2text ("add-drive-with-if", _("add a drive specifying the QEMU block emulation to use"), "=head1 SYNOPSIS\n\n add-drive-with-if filename iface\n\n=head1 DESCRIPTION\n\nThis is the same as C<add_drive> but it allows you\nto specify the QEMU interface emulation to use at run time.\n\nThis function is deprecated.\nIn new code, use the C<add_drive_opts> call instead.\n\nDeprecated functions will not be removed from the API, but the\nfact that they are deprecated indicates that there are problems\nwith correct use of these functions.");
     return 0;
   }
   else
   if (STRCASEEQ (cmd, "add_drive_ro_with_if") || STRCASEEQ (cmd, "add-drive-ro-with-if")) {
-    pod2text ("add-drive-ro-with-if", _("add a drive read-only specifying the QEMU block emulation to use"), "=head1 SYNOPSIS\n\n add-drive-ro-with-if filename iface\n\n=head1 DESCRIPTION\n\nThis is the same as C<add_drive_ro> but it allows you\nto specify the QEMU interface emulation to use at run time.");
+    pod2text ("add-drive-ro-with-if", _("add a drive read-only specifying the QEMU block emulation to use"), "=head1 SYNOPSIS\n\n add-drive-ro-with-if filename iface\n\n=head1 DESCRIPTION\n\nThis is the same as C<add_drive_ro> but it allows you\nto specify the QEMU interface emulation to use at run time.\n\nThis function is deprecated.\nIn new code, use the C<add_drive_opts> call instead.\n\nDeprecated functions will not be removed from the API, but the\nfact that they are deprecated indicates that there are problems\nwith correct use of these functions.");
     return 0;
   }
   else
@@ -693,6 +694,11 @@
     return 0;
   }
   else
+  if (STRCASEEQ (cmd, "add_drive_opts") || STRCASEEQ (cmd, "add-drive-opts") || STRCASEEQ (cmd, "add")) {
+    pod2text ("add-drive-opts", _("add an image to examine or modify"), "=head1 SYNOPSIS\n\n add-drive-opts filename [readonly:..] [format:..] [iface:..]\n\n=head1 DESCRIPTION\n\nThis function adds a virtual machine disk image C<filename> to\nlibguestfs.  The first time you call this function, the disk\nappears as C</dev/sda>, the second time as C</dev/sdb>, and\nso on.\n\nYou don't necessarily need to be root when using libguestfs.  However\nyou obviously do need sufficient permissions to access the filename\nfor whatever operations you want to perform (ie. read access if you\njust want to read the image or write access if you want to modify the\nimage).\n\nThis call checks that C<filename> exists.\n\nThe optional arguments are:\n\n=over 4\n\n=item C<readonly>\n\nIf true then the image is treated as read-only.  Writes are still\nallowed, but they are stored in a temporary snapshot overlay which\nis discarded at the end.  The disk that you add is not modified.\n\n=item C<format>\n\nThis forces the image format.  If you omit this (or use C<add_drive>\nor C<add_drive_ro>) then the format is automatically detected.\nPossible formats include C<raw> and C<qcow2>.\n\nAutomatic detection of the format opens you up to a potential\nsecurity hole when dealing with untrusted raw-format images.\nSee CVE-2010-3851 and RHBZ#642934.  Specifying the format closes\nthis security hole.\n\n=item C<iface>\n\nThis rarely-used option lets you emulate the behaviour of the\ndeprecated C<add_drive_with_if> call (q.v.)\n\n=back\n\nYou can use 'add' as an alias for this command.");
+    return 0;
+  }
+  else
   if (STRCASEEQ (cmd, "mount")) {
     pod2text ("mount", _("mount a guest disk at a position in the filesystem"), "=head1 SYNOPSIS\n\n mount device mountpoint\n\n=head1 DESCRIPTION\n\nMount a guest disk at a position in the filesystem.  Block devices\nare named C</dev/sda>, C</dev/sdb> and so on, as they were added to\nthe guest.  If those block devices contain partitions, they will have\nthe usual names (eg. C</dev/sda1>).  Also LVM C</dev/VG/LV>-style\nnames can be used.\n\nThe rules are the same as for L<mount(2)>:  A filesystem must\nfirst be mounted on C</> before others can be mounted.  Other\nfilesystems can only be mounted on directories which already\nexist.\n\nThe mounted filesystem is writable, if we have sufficient permissions\non the underlying device.\n\nB<Important note:>\nWhen you use this call, the filesystem options C<sync> and C<noatime>\nare set implicitly.  This was originally done because we thought it\nwould improve reliability, but it turns out that I<-o sync> has a\nvery large negative performance impact and negligible effect on\nreliability.  Therefore we recommend that you avoid using\nC<mount> in any code that needs performance, and instead\nuse C<mount_options> (use an empty string for the first\nparameter if you don't want any options).");
     return 0;
@@ -2348,6 +2354,7 @@
 static int run_launch (const char *cmd, size_t argc, char *argv[])
 {
   int r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -2360,6 +2367,7 @@
 static int run_kill_subprocess (const char *cmd, size_t argc, char *argv[])
 {
   int r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -2373,12 +2381,13 @@
 {
   int r;
   const char *filename;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   filename = argv[i++];
   r = guestfs_add_drive (g, filename);
   return r;
@@ -2388,12 +2397,13 @@
 {
   int r;
   const char *filename;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   filename = argv[i++];
   r = guestfs_add_cdrom (g, filename);
   return r;
@@ -2403,12 +2413,13 @@
 {
   int r;
   const char *filename;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   filename = argv[i++];
   r = guestfs_add_drive_ro (g, filename);
   return r;
@@ -2419,12 +2430,13 @@
   int r;
   const char *qemuparam;
   const char *qemuvalue;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   qemuparam = argv[i++];
   qemuvalue = STRNEQ (argv[i], "") ? argv[i] : NULL;
   i++;
@@ -2436,12 +2448,13 @@
 {
   int r;
   const char *qemu;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   qemu = STRNEQ (argv[i], "") ? argv[i] : NULL;
   i++;
   r = guestfs_set_qemu (g, qemu);
@@ -2451,6 +2464,7 @@
 static int run_get_qemu (const char *cmd, size_t argc, char *argv[])
 {
   const char *r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -2466,12 +2480,13 @@
 {
   int r;
   const char *searchpath;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   searchpath = STRNEQ (argv[i], "") ? argv[i] : NULL;
   i++;
   r = guestfs_set_path (g, searchpath);
@@ -2481,6 +2496,7 @@
 static int run_get_path (const char *cmd, size_t argc, char *argv[])
 {
   const char *r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -2496,12 +2512,13 @@
 {
   int r;
   const char *append;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   append = STRNEQ (argv[i], "") ? argv[i] : NULL;
   i++;
   r = guestfs_set_append (g, append);
@@ -2511,6 +2528,7 @@
 static int run_get_append (const char *cmd, size_t argc, char *argv[])
 {
   const char *r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -2525,12 +2543,13 @@
 {
   int r;
   int autosync;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   autosync = is_true (argv[i++]) ? 1 : 0;
   r = guestfs_set_autosync (g, autosync);
   return r;
@@ -2539,6 +2558,7 @@
 static int run_get_autosync (const char *cmd, size_t argc, char *argv[])
 {
   int r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -2554,12 +2574,13 @@
 {
   int r;
   int verbose;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   verbose = is_true (argv[i++]) ? 1 : 0;
   r = guestfs_set_verbose (g, verbose);
   return r;
@@ -2568,6 +2589,7 @@
 static int run_get_verbose (const char *cmd, size_t argc, char *argv[])
 {
   int r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -2582,6 +2604,7 @@
 static int run_is_ready (const char *cmd, size_t argc, char *argv[])
 {
   int r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -2596,6 +2619,7 @@
 static int run_is_config (const char *cmd, size_t argc, char *argv[])
 {
   int r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -2610,6 +2634,7 @@
 static int run_is_launching (const char *cmd, size_t argc, char *argv[])
 {
   int r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -2624,6 +2649,7 @@
 static int run_is_busy (const char *cmd, size_t argc, char *argv[])
 {
   int r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -2638,6 +2664,7 @@
 static int run_get_state (const char *cmd, size_t argc, char *argv[])
 {
   int r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -2653,12 +2680,13 @@
 {
   int r;
   int memsize;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   {
     strtol_error xerr;
     long long r;
@@ -2685,6 +2713,7 @@
 static int run_get_memsize (const char *cmd, size_t argc, char *argv[])
 {
   int r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -2699,6 +2728,7 @@
 static int run_get_pid (const char *cmd, size_t argc, char *argv[])
 {
   int r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -2713,6 +2743,7 @@
 static int run_version (const char *cmd, size_t argc, char *argv[])
 {
   struct guestfs_version *r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -2729,12 +2760,13 @@
 {
   int r;
   int selinux;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   selinux = is_true (argv[i++]) ? 1 : 0;
   r = guestfs_set_selinux (g, selinux);
   return r;
@@ -2743,6 +2775,7 @@
 static int run_get_selinux (const char *cmd, size_t argc, char *argv[])
 {
   int r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -2758,12 +2791,13 @@
 {
   int r;
   int trace;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   trace = is_true (argv[i++]) ? 1 : 0;
   r = guestfs_set_trace (g, trace);
   return r;
@@ -2772,6 +2806,7 @@
 static int run_get_trace (const char *cmd, size_t argc, char *argv[])
 {
   int r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -2787,12 +2822,13 @@
 {
   int r;
   int direct;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   direct = is_true (argv[i++]) ? 1 : 0;
   r = guestfs_set_direct (g, direct);
   return r;
@@ -2801,6 +2837,7 @@
 static int run_get_direct (const char *cmd, size_t argc, char *argv[])
 {
   int r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -2816,12 +2853,13 @@
 {
   int r;
   int recoveryproc;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   recoveryproc = is_true (argv[i++]) ? 1 : 0;
   r = guestfs_set_recovery_proc (g, recoveryproc);
   return r;
@@ -2830,6 +2868,7 @@
 static int run_get_recovery_proc (const char *cmd, size_t argc, char *argv[])
 {
   int r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -2846,12 +2885,13 @@
   int r;
   const char *filename;
   const char *iface;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   filename = argv[i++];
   iface = argv[i++];
   r = guestfs_add_drive_with_if (g, filename, iface);
@@ -2863,12 +2903,13 @@
   int r;
   const char *filename;
   const char *iface;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   filename = argv[i++];
   iface = argv[i++];
   r = guestfs_add_drive_ro_with_if (g, filename, iface);
@@ -2879,12 +2920,13 @@
 {
   char *r;
   char *filename;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   filename = resolve_win_path (argv[i++]);
   if (filename == NULL) return -1;
   r = guestfs_file_architecture (g, filename);
@@ -2898,6 +2940,7 @@
 static int run_inspect_os (const char *cmd, size_t argc, char *argv[])
 {
   char **r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -2914,12 +2957,13 @@
 {
   char *r;
   const char *root;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   root = argv[i++];
   r = guestfs_inspect_get_type (g, root);
   if (r == NULL) return -1;
@@ -2932,12 +2976,13 @@
 {
   char *r;
   const char *root;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   root = argv[i++];
   r = guestfs_inspect_get_arch (g, root);
   if (r == NULL) return -1;
@@ -2950,12 +2995,13 @@
 {
   char *r;
   const char *root;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   root = argv[i++];
   r = guestfs_inspect_get_distro (g, root);
   if (r == NULL) return -1;
@@ -2968,12 +3014,13 @@
 {
   int r;
   const char *root;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   root = argv[i++];
   r = guestfs_inspect_get_major_version (g, root);
   if (r == -1) return -1;
@@ -2985,12 +3032,13 @@
 {
   int r;
   const char *root;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   root = argv[i++];
   r = guestfs_inspect_get_minor_version (g, root);
   if (r == -1) return -1;
@@ -3002,12 +3050,13 @@
 {
   char *r;
   const char *root;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   root = argv[i++];
   r = guestfs_inspect_get_product_name (g, root);
   if (r == NULL) return -1;
@@ -3020,12 +3069,13 @@
 {
   char **r;
   const char *root;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   root = argv[i++];
   r = guestfs_inspect_get_mountpoints (g, root);
   if (r == NULL) return -1;
@@ -3038,12 +3088,13 @@
 {
   char **r;
   const char *root;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   root = argv[i++];
   r = guestfs_inspect_get_filesystems (g, root);
   if (r == NULL) return -1;
@@ -3056,12 +3107,13 @@
 {
   int r;
   int network;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   network = is_true (argv[i++]) ? 1 : 0;
   r = guestfs_set_network (g, network);
   return r;
@@ -3070,6 +3122,7 @@
 static int run_get_network (const char *cmd, size_t argc, char *argv[])
 {
   int r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -3084,6 +3137,7 @@
 static int run_list_filesystems (const char *cmd, size_t argc, char *argv[])
 {
   char **r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -3096,17 +3150,63 @@
   return 0;
 }
 
+static int run_add_drive_opts (const char *cmd, size_t argc, char *argv[])
+{
+  int r;
+  const char *filename;
+  struct guestfs_add_drive_opts_argv optargs_s = { .bitmask = 0 };
+  struct guestfs_add_drive_opts_argv *optargs = &optargs_s;
+  size_t i = 0;
+
+  if (argc < 1 || argc > 4) {
+    fprintf (stderr, _("%s should have %d-%d parameter(s)\n"), cmd, 1, 4);
+    fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
+    return -1;
+  }
+  filename = argv[i++];
+
+  for (; i < argc; ++i) {
+    uint64_t this_mask;
+    const char *this_arg;
+    if (STRPREFIX (argv[i], "readonly:")) {
+      optargs_s.readonly = is_true (&argv[i][9]) ? 1 : 0;
+      this_mask = GUESTFS_ADD_DRIVE_OPTS_READONLY_BITMASK;
+      this_arg = "readonly";
+    }
+    if (STRPREFIX (argv[i], "format:")) {
+      optargs_s.format = &argv[i][7];
+      this_mask = GUESTFS_ADD_DRIVE_OPTS_FORMAT_BITMASK;
+      this_arg = "format";
+    }
+    if (STRPREFIX (argv[i], "iface:")) {
+      optargs_s.iface = &argv[i][6];
+      this_mask = GUESTFS_ADD_DRIVE_OPTS_IFACE_BITMASK;
+      this_arg = "iface";
+    }
+    if (optargs_s.bitmask & this_mask) {
+      fprintf (stderr, _("%s: optional argument %s given twice\n"),
+               cmd, this_arg);
+      return -1;
+    }
+    optargs_s.bitmask |= this_mask;
+  }
+
+  r = guestfs_add_drive_opts_argv (g, filename, optargs);
+  return r;
+}
+
 static int run_mount (const char *cmd, size_t argc, char *argv[])
 {
   int r;
   const char *device;
   const char *mountpoint;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   mountpoint = argv[i++];
   r = guestfs_mount (g, device, mountpoint);
@@ -3116,6 +3216,7 @@
 static int run_sync (const char *cmd, size_t argc, char *argv[])
 {
   int r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -3129,12 +3230,13 @@
 {
   int r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_touch (g, path);
@@ -3146,12 +3248,13 @@
 {
   char *r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_cat (g, path);
@@ -3166,12 +3269,13 @@
 {
   char *r;
   char *directory;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   directory = resolve_win_path (argv[i++]);
   if (directory == NULL) return -1;
   r = guestfs_ll (g, directory);
@@ -3186,12 +3290,13 @@
 {
   char **r;
   char *directory;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   directory = resolve_win_path (argv[i++]);
   if (directory == NULL) return -1;
   r = guestfs_ls (g, directory);
@@ -3205,6 +3310,7 @@
 static int run_list_devices (const char *cmd, size_t argc, char *argv[])
 {
   char **r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -3220,6 +3326,7 @@
 static int run_list_partitions (const char *cmd, size_t argc, char *argv[])
 {
   char **r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -3235,6 +3342,7 @@
 static int run_pvs (const char *cmd, size_t argc, char *argv[])
 {
   char **r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -3250,6 +3358,7 @@
 static int run_vgs (const char *cmd, size_t argc, char *argv[])
 {
   char **r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -3265,6 +3374,7 @@
 static int run_lvs (const char *cmd, size_t argc, char *argv[])
 {
   char **r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -3280,6 +3390,7 @@
 static int run_pvs_full (const char *cmd, size_t argc, char *argv[])
 {
   struct guestfs_lvm_pv_list *r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -3295,6 +3406,7 @@
 static int run_vgs_full (const char *cmd, size_t argc, char *argv[])
 {
   struct guestfs_lvm_vg_list *r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -3310,6 +3422,7 @@
 static int run_lvs_full (const char *cmd, size_t argc, char *argv[])
 {
   struct guestfs_lvm_lv_list *r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -3326,12 +3439,13 @@
 {
   char **r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_read_lines (g, path);
@@ -3347,12 +3461,13 @@
   int r;
   char *root;
   int flags;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   root = resolve_win_path (argv[i++]);
   if (root == NULL) return -1;
   {
@@ -3382,6 +3497,7 @@
 static int run_aug_close (const char *cmd, size_t argc, char *argv[])
 {
   int r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -3396,12 +3512,13 @@
   int r;
   const char *name;
   const char *expr;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   name = argv[i++];
   expr = STRNEQ (argv[i], "") ? argv[i] : NULL;
   i++;
@@ -3417,12 +3534,13 @@
   const char *name;
   const char *expr;
   const char *val;
+  size_t i = 0;
+
   if (argc != 3) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 3);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   name = argv[i++];
   expr = argv[i++];
   val = argv[i++];
@@ -3437,12 +3555,13 @@
 {
   char *r;
   const char *augpath;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   augpath = argv[i++];
   r = guestfs_aug_get (g, augpath);
   if (r == NULL) return -1;
@@ -3456,12 +3575,13 @@
   int r;
   const char *augpath;
   const char *val;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   augpath = argv[i++];
   val = argv[i++];
   r = guestfs_aug_set (g, augpath, val);
@@ -3474,12 +3594,13 @@
   const char *augpath;
   const char *label;
   int before;
+  size_t i = 0;
+
   if (argc != 3) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 3);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   augpath = argv[i++];
   label = argv[i++];
   before = is_true (argv[i++]) ? 1 : 0;
@@ -3491,12 +3612,13 @@
 {
   int r;
   const char *augpath;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   augpath = argv[i++];
   r = guestfs_aug_rm (g, augpath);
   if (r == -1) return -1;
@@ -3509,12 +3631,13 @@
   int r;
   const char *src;
   const char *dest;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   src = argv[i++];
   dest = argv[i++];
   r = guestfs_aug_mv (g, src, dest);
@@ -3525,12 +3648,13 @@
 {
   char **r;
   const char *augpath;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   augpath = argv[i++];
   r = guestfs_aug_match (g, augpath);
   if (r == NULL) return -1;
@@ -3542,6 +3666,7 @@
 static int run_aug_save (const char *cmd, size_t argc, char *argv[])
 {
   int r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -3554,6 +3679,7 @@
 static int run_aug_load (const char *cmd, size_t argc, char *argv[])
 {
   int r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -3567,12 +3693,13 @@
 {
   char **r;
   const char *augpath;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   augpath = argv[i++];
   r = guestfs_aug_ls (g, augpath);
   if (r == NULL) return -1;
@@ -3585,12 +3712,13 @@
 {
   int r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_rm (g, path);
@@ -3602,12 +3730,13 @@
 {
   int r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_rmdir (g, path);
@@ -3619,12 +3748,13 @@
 {
   int r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_rm_rf (g, path);
@@ -3636,12 +3766,13 @@
 {
   int r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_mkdir (g, path);
@@ -3653,12 +3784,13 @@
 {
   int r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_mkdir_p (g, path);
@@ -3671,12 +3803,13 @@
   int r;
   int mode;
   char *path;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   {
     strtol_error xerr;
     long long r;
@@ -3709,12 +3842,13 @@
   int owner;
   int group;
   char *path;
+  size_t i = 0;
+
   if (argc != 3) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 3);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   {
     strtol_error xerr;
     long long r;
@@ -3764,12 +3898,13 @@
 {
   int r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_exists (g, path);
@@ -3783,12 +3918,13 @@
 {
   int r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_is_file (g, path);
@@ -3802,12 +3938,13 @@
 {
   int r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_is_dir (g, path);
@@ -3821,12 +3958,13 @@
 {
   int r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_pvcreate (g, device);
   return r;
@@ -3837,12 +3975,13 @@
   int r;
   const char *volgroup;
   char **physvols;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   volgroup = argv[i++];
   physvols = parse_string_list (argv[i++]);
   if (physvols == NULL) return -1;
@@ -3857,12 +3996,13 @@
   const char *logvol;
   const char *volgroup;
   int mbytes;
+  size_t i = 0;
+
   if (argc != 3) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 3);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   logvol = argv[i++];
   volgroup = argv[i++];
   {
@@ -3893,12 +4033,13 @@
   int r;
   const char *fstype;
   const char *device;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   fstype = argv[i++];
   device = argv[i++];
   r = guestfs_mkfs (g, fstype, device);
@@ -3913,12 +4054,13 @@
   int heads;
   int sectors;
   char **lines;
+  size_t i = 0;
+
   if (argc != 5) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 5);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   {
     strtol_error xerr;
@@ -3990,12 +4132,13 @@
   char *path;
   const char *content;
   int size;
+  size_t i = 0;
+
   if (argc != 3) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 3);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   content = argv[i++];
@@ -4027,12 +4170,13 @@
 {
   int r;
   const char *pathordevice;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   pathordevice = argv[i++];
   r = guestfs_umount (g, pathordevice);
   return r;
@@ -4041,6 +4185,7 @@
 static int run_mounts (const char *cmd, size_t argc, char *argv[])
 {
   char **r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -4056,6 +4201,7 @@
 static int run_umount_all (const char *cmd, size_t argc, char *argv[])
 {
   int r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -4068,6 +4214,7 @@
 static int run_lvm_remove_all (const char *cmd, size_t argc, char *argv[])
 {
   int r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -4081,12 +4228,13 @@
 {
   char *r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_file (g, path);
@@ -4101,12 +4249,13 @@
 {
   char *r;
   char **arguments;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   arguments = parse_string_list (argv[i++]);
   if (arguments == NULL) return -1;
   r = guestfs_command (g, arguments);
@@ -4121,12 +4270,13 @@
 {
   char **r;
   char **arguments;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   arguments = parse_string_list (argv[i++]);
   if (arguments == NULL) return -1;
   r = guestfs_command_lines (g, arguments);
@@ -4141,12 +4291,13 @@
 {
   struct guestfs_stat *r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_stat (g, path);
@@ -4161,12 +4312,13 @@
 {
   struct guestfs_stat *r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_lstat (g, path);
@@ -4181,12 +4333,13 @@
 {
   struct guestfs_statvfs *r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_statvfs (g, path);
@@ -4201,12 +4354,13 @@
 {
   char **r;
   const char *device;
-  if (argc != 1) {
+  size_t i = 0;
+
+  if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_tune2fs_l (g, device);
   if (r == NULL) return -1;
@@ -4219,12 +4373,13 @@
 {
   int r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_blockdev_setro (g, device);
   return r;
@@ -4234,12 +4389,13 @@
 {
   int r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_blockdev_setrw (g, device);
   return r;
@@ -4249,12 +4405,13 @@
 {
   int r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_blockdev_getro (g, device);
   if (r == -1) return -1;
@@ -4266,12 +4423,13 @@
 {
   int r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_blockdev_getss (g, device);
   if (r == -1) return -1;
@@ -4283,12 +4441,13 @@
 {
   int r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_blockdev_getbsz (g, device);
   if (r == -1) return -1;
@@ -4301,12 +4460,13 @@
   int r;
   const char *device;
   int blocksize;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   {
     strtol_error xerr;
@@ -4335,12 +4495,13 @@
 {
   int64_t r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_blockdev_getsz (g, device);
   if (r == -1) return -1;
@@ -4352,12 +4513,13 @@
 {
   int64_t r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_blockdev_getsize64 (g, device);
   if (r == -1) return -1;
@@ -4369,12 +4531,13 @@
 {
   int r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_blockdev_flushbufs (g, device);
   return r;
@@ -4384,12 +4547,13 @@
 {
   int r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_blockdev_rereadpt (g, device);
   return r;
@@ -4400,12 +4564,13 @@
   int r;
   char *filename;
   char *remotefilename;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   filename = file_in (argv[i++]);
   if (filename == NULL) return -1;
   remotefilename = resolve_win_path (argv[i++]);
@@ -4421,12 +4586,13 @@
   int r;
   char *remotefilename;
   char *filename;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   remotefilename = resolve_win_path (argv[i++]);
   if (remotefilename == NULL) return -1;
   filename = file_out (argv[i++]);
@@ -4442,12 +4608,13 @@
   char *r;
   const char *csumtype;
   char *path;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   csumtype = argv[i++];
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
@@ -4464,12 +4631,13 @@
   int r;
   char *tarfile;
   char *directory;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   tarfile = file_in (argv[i++]);
   if (tarfile == NULL) return -1;
   directory = resolve_win_path (argv[i++]);
@@ -4485,12 +4653,13 @@
   int r;
   const char *directory;
   char *tarfile;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   directory = argv[i++];
   tarfile = file_out (argv[i++]);
   if (tarfile == NULL) return -1;
@@ -4504,12 +4673,13 @@
   int r;
   char *tarball;
   char *directory;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   tarball = file_in (argv[i++]);
   if (tarball == NULL) return -1;
   directory = resolve_win_path (argv[i++]);
@@ -4525,12 +4695,13 @@
   int r;
   char *directory;
   char *tarball;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   directory = resolve_win_path (argv[i++]);
   if (directory == NULL) return -1;
   tarball = file_out (argv[i++]);
@@ -4546,12 +4717,13 @@
   int r;
   const char *device;
   const char *mountpoint;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   mountpoint = argv[i++];
   r = guestfs_mount_ro (g, device, mountpoint);
@@ -4564,12 +4736,13 @@
   const char *options;
   const char *device;
   const char *mountpoint;
+  size_t i = 0;
+
   if (argc != 3) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 3);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   options = argv[i++];
   device = argv[i++];
   mountpoint = argv[i++];
@@ -4584,12 +4757,13 @@
   const char *vfstype;
   const char *device;
   const char *mountpoint;
+  size_t i = 0;
+
   if (argc != 4) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 4);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   options = argv[i++];
   vfstype = argv[i++];
   device = argv[i++];
@@ -4603,12 +4777,13 @@
   char *r;
   const char *subcmd;
   char **extraargs;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   subcmd = argv[i++];
   extraargs = parse_string_list (argv[i++]);
   if (extraargs == NULL) return -1;
@@ -4624,12 +4799,13 @@
 {
   int r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_lvremove (g, device);
   return r;
@@ -4639,12 +4815,13 @@
 {
   int r;
   const char *vgname;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   vgname = argv[i++];
   r = guestfs_vgremove (g, vgname);
   return r;
@@ -4654,12 +4831,13 @@
 {
   int r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_pvremove (g, device);
   return r;
@@ -4670,12 +4848,13 @@
   int r;
   const char *device;
   const char *label;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   label = argv[i++];
   r = guestfs_set_e2label (g, device, label);
@@ -4686,12 +4865,13 @@
 {
   char *r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_get_e2label (g, device);
   if (r == NULL) return -1;
@@ -4705,12 +4885,13 @@
   int r;
   const char *device;
   const char *uuid;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   uuid = argv[i++];
   r = guestfs_set_e2uuid (g, device, uuid);
@@ -4721,12 +4902,13 @@
 {
   char *r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_get_e2uuid (g, device);
   if (r == NULL) return -1;
@@ -4740,12 +4922,13 @@
   int r;
   const char *fstype;
   const char *device;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   fstype = argv[i++];
   device = argv[i++];
   r = guestfs_fsck (g, fstype, device);
@@ -4758,12 +4941,13 @@
 {
   int r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_zero (g, device);
   return r;
@@ -4774,12 +4958,13 @@
   int r;
   char *root;
   const char *device;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   root = resolve_win_path (argv[i++]);
   if (root == NULL) return -1;
   device = argv[i++];
@@ -4793,12 +4978,13 @@
   int r;
   char *src;
   char *dest;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   src = resolve_win_path (argv[i++]);
   if (src == NULL) return -1;
   dest = resolve_win_path (argv[i++]);
@@ -4814,12 +5000,13 @@
   int r;
   char *src;
   char *dest;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   src = resolve_win_path (argv[i++]);
   if (src == NULL) return -1;
   dest = resolve_win_path (argv[i++]);
@@ -4835,12 +5022,13 @@
   int r;
   char *src;
   char *dest;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   src = resolve_win_path (argv[i++]);
   if (src == NULL) return -1;
   dest = resolve_win_path (argv[i++]);
@@ -4855,12 +5043,13 @@
 {
   int r;
   int whattodrop;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   {
     strtol_error xerr;
     long long r;
@@ -4887,6 +5076,7 @@
 static int run_dmesg (const char *cmd, size_t argc, char *argv[])
 {
   char *r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -4902,6 +5092,7 @@
 static int run_ping_daemon (const char *cmd, size_t argc, char *argv[])
 {
   int r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -4916,12 +5107,13 @@
   int r;
   char *file1;
   char *file2;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   file1 = resolve_win_path (argv[i++]);
   if (file1 == NULL) return -1;
   file2 = resolve_win_path (argv[i++]);
@@ -4938,12 +5130,13 @@
 {
   char **r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_strings (g, path);
@@ -4959,12 +5152,13 @@
   char **r;
   const char *encoding;
   char *path;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   encoding = argv[i++];
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
@@ -4980,12 +5174,13 @@
 {
   char *r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_hexdump (g, path);
@@ -5000,12 +5195,13 @@
 {
   int r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_zerofree (g, device);
   return r;
@@ -5015,12 +5211,13 @@
 {
   int r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_pvresize (g, device);
   return r;
@@ -5035,12 +5232,13 @@
   int heads;
   int sectors;
   const char *line;
+  size_t i = 0;
+
   if (argc != 6) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 6);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   {
     strtol_error xerr;
@@ -5127,12 +5325,13 @@
 {
   char *r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_sfdisk_l (g, device);
   if (r == NULL) return -1;
@@ -5145,12 +5344,13 @@
 {
   char *r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_sfdisk_kernel_geometry (g, device);
   if (r == NULL) return -1;
@@ -5163,12 +5363,13 @@
 {
   char *r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_sfdisk_disk_geometry (g, device);
   if (r == NULL) return -1;
@@ -5181,12 +5382,13 @@
 {
   int r;
   int activate;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   activate = is_true (argv[i++]) ? 1 : 0;
   r = guestfs_vg_activate_all (g, activate);
   return r;
@@ -5197,12 +5399,13 @@
   int r;
   int activate;
   char **volgroups;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   activate = is_true (argv[i++]) ? 1 : 0;
   volgroups = parse_string_list (argv[i++]);
   if (volgroups == NULL) return -1;
@@ -5216,12 +5419,13 @@
   int r;
   const char *device;
   int mbytes;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   {
     strtol_error xerr;
@@ -5250,12 +5454,13 @@
 {
   int r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_resize2fs (g, device);
   return r;
@@ -5265,12 +5470,13 @@
 {
   char **r;
   char *directory;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   directory = resolve_win_path (argv[i++]);
   if (directory == NULL) return -1;
   r = guestfs_find (g, directory);
@@ -5285,12 +5491,13 @@
 {
   int r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_e2fsck_f (g, device);
   return r;
@@ -5300,12 +5507,13 @@
 {
   int r;
   int secs;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   {
     strtol_error xerr;
     long long r;
@@ -5334,12 +5542,13 @@
   int r;
   int rw;
   const char *device;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   rw = is_true (argv[i++]) ? 1 : 0;
   device = argv[i++];
   r = guestfs_ntfs_3g_probe (g, rw, device);
@@ -5352,12 +5561,13 @@
 {
   char *r;
   const char *command;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   command = argv[i++];
   r = guestfs_sh (g, command);
   if (r == NULL) return -1;
@@ -5370,12 +5580,13 @@
 {
   char **r;
   const char *command;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   command = argv[i++];
   r = guestfs_sh_lines (g, command);
   if (r == NULL) return -1;
@@ -5388,12 +5599,13 @@
 {
   char **r;
   char *pattern;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   pattern = resolve_win_path (argv[i++]);
   if (pattern == NULL) return -1;
   r = guestfs_glob_expand (g, pattern);
@@ -5408,12 +5620,13 @@
 {
   int r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_scrub_device (g, device);
   return r;
@@ -5423,12 +5636,13 @@
 {
   int r;
   char *file;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   file = resolve_win_path (argv[i++]);
   if (file == NULL) return -1;
   r = guestfs_scrub_file (g, file);
@@ -5440,12 +5654,13 @@
 {
   int r;
   char *dir;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   dir = resolve_win_path (argv[i++]);
   if (dir == NULL) return -1;
   r = guestfs_scrub_freespace (g, dir);
@@ -5457,12 +5672,13 @@
 {
   char *r;
   char *template;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   template = resolve_win_path (argv[i++]);
   if (template == NULL) return -1;
   r = guestfs_mkdtemp (g, template);
@@ -5477,12 +5693,13 @@
 {
   int r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_wc_l (g, path);
@@ -5496,12 +5713,13 @@
 {
   int r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_wc_w (g, path);
@@ -5515,12 +5733,13 @@
 {
   int r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_wc_c (g, path);
@@ -5534,12 +5753,13 @@
 {
   char **r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_head (g, path);
@@ -5555,12 +5775,13 @@
   char **r;
   int nrlines;
   char *path;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   {
     strtol_error xerr;
     long long r;
@@ -5594,12 +5815,13 @@
 {
   char **r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_tail (g, path);
@@ -5615,12 +5837,13 @@
   char **r;
   int nrlines;
   char *path;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   {
     strtol_error xerr;
     long long r;
@@ -5653,6 +5876,7 @@
 static int run_df (const char *cmd, size_t argc, char *argv[])
 {
   char *r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -5668,6 +5892,7 @@
 static int run_df_h (const char *cmd, size_t argc, char *argv[])
 {
   char *r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -5684,12 +5909,13 @@
 {
   int64_t r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_du (g, path);
@@ -5703,12 +5929,13 @@
 {
   char **r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_initrd_list (g, path);
@@ -5724,12 +5951,13 @@
   int r;
   char *file;
   char *mountpoint;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   file = resolve_win_path (argv[i++]);
   if (file == NULL) return -1;
   mountpoint = resolve_win_path (argv[i++]);
@@ -5744,12 +5972,13 @@
 {
   int r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_mkswap (g, device);
   return r;
@@ -5760,12 +5989,13 @@
   int r;
   const char *label;
   const char *device;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   label = argv[i++];
   device = argv[i++];
   r = guestfs_mkswap_L (g, label, device);
@@ -5777,12 +6007,13 @@
   int r;
   const char *uuid;
   const char *device;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   uuid = argv[i++];
   device = argv[i++];
   r = guestfs_mkswap_U (g, uuid, device);
@@ -5796,12 +6027,13 @@
   int devmajor;
   int devminor;
   char *path;
+  size_t i = 0;
+
   if (argc != 4) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 4);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   {
     strtol_error xerr;
     long long r;
@@ -5871,12 +6103,13 @@
   int r;
   int mode;
   char *path;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   {
     strtol_error xerr;
     long long r;
@@ -5910,12 +6143,13 @@
   int devmajor;
   int devminor;
   char *path;
+  size_t i = 0;
+
   if (argc != 4) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 4);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   {
     strtol_error xerr;
     long long r;
@@ -5987,12 +6221,13 @@
   int devmajor;
   int devminor;
   char *path;
+  size_t i = 0;
+
   if (argc != 4) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 4);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   {
     strtol_error xerr;
     long long r;
@@ -6061,12 +6296,13 @@
 {
   int r;
   int mask;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   {
     strtol_error xerr;
     long long r;
@@ -6096,12 +6332,13 @@
 {
   struct guestfs_dirent_list *r;
   char *dir;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   dir = resolve_win_path (argv[i++]);
   if (dir == NULL) return -1;
   r = guestfs_readdir (g, dir);
@@ -6117,12 +6354,13 @@
   int r;
   const char *device;
   char **lines;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   lines = parse_string_list (argv[i++]);
   if (lines == NULL) return -1;
@@ -6136,12 +6374,13 @@
   char *r;
   const char *meth;
   char *path;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   meth = argv[i++];
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
@@ -6157,12 +6396,13 @@
 {
   struct guestfs_xattr_list *r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_getxattrs (g, path);
@@ -6177,12 +6417,13 @@
 {
   struct guestfs_xattr_list *r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_lgetxattrs (g, path);
@@ -6200,12 +6441,13 @@
   const char *val;
   int vallen;
   char *path;
+  size_t i = 0;
+
   if (argc != 4) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 4);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   xattr = argv[i++];
   val = argv[i++];
   {
@@ -6241,12 +6483,13 @@
   const char *val;
   int vallen;
   char *path;
+  size_t i = 0;
+
   if (argc != 4) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 4);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   xattr = argv[i++];
   val = argv[i++];
   {
@@ -6280,12 +6523,13 @@
   int r;
   const char *xattr;
   char *path;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   xattr = argv[i++];
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
@@ -6299,12 +6543,13 @@
   int r;
   const char *xattr;
   char *path;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   xattr = argv[i++];
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
@@ -6316,6 +6561,7 @@
 static int run_mountpoints (const char *cmd, size_t argc, char *argv[])
 {
   char **r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -6332,12 +6578,13 @@
 {
   int r;
   const char *exemptpath;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   exemptpath = argv[i++];
   r = guestfs_mkmountpoint (g, exemptpath);
   return r;
@@ -6347,12 +6594,13 @@
 {
   int r;
   const char *exemptpath;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   exemptpath = argv[i++];
   r = guestfs_rmmountpoint (g, exemptpath);
   return r;
@@ -6363,12 +6611,13 @@
   char *r;
   size_t size;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_read_file (g, path, &size);
@@ -6388,12 +6637,13 @@
   char **r;
   const char *regex;
   char *path;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   regex = argv[i++];
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
@@ -6410,12 +6660,13 @@
   char **r;
   const char *regex;
   char *path;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   regex = argv[i++];
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
@@ -6432,12 +6683,13 @@
   char **r;
   const char *pattern;
   char *path;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   pattern = argv[i++];
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
@@ -6454,12 +6706,13 @@
   char **r;
   const char *regex;
   char *path;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   regex = argv[i++];
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
@@ -6476,12 +6729,13 @@
   char **r;
   const char *regex;
   char *path;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   regex = argv[i++];
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
@@ -6498,12 +6752,13 @@
   char **r;
   const char *pattern;
   char *path;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   pattern = argv[i++];
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
@@ -6520,12 +6775,13 @@
   char **r;
   const char *regex;
   char *path;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   regex = argv[i++];
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
@@ -6542,12 +6798,13 @@
   char **r;
   const char *regex;
   char *path;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   regex = argv[i++];
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
@@ -6564,12 +6821,13 @@
   char **r;
   const char *pattern;
   char *path;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   pattern = argv[i++];
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
@@ -6586,12 +6844,13 @@
   char **r;
   const char *regex;
   char *path;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   regex = argv[i++];
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
@@ -6608,12 +6867,13 @@
   char **r;
   const char *regex;
   char *path;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   regex = argv[i++];
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
@@ -6630,12 +6890,13 @@
   char **r;
   const char *pattern;
   char *path;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   pattern = argv[i++];
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
@@ -6651,12 +6912,13 @@
 {
   char *r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_realpath (g, path);
@@ -6672,12 +6934,13 @@
   int r;
   const char *target;
   char *linkname;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   target = argv[i++];
   linkname = resolve_win_path (argv[i++]);
   if (linkname == NULL) return -1;
@@ -6691,12 +6954,13 @@
   int r;
   const char *target;
   char *linkname;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   target = argv[i++];
   linkname = resolve_win_path (argv[i++]);
   if (linkname == NULL) return -1;
@@ -6710,12 +6974,13 @@
   int r;
   const char *target;
   char *linkname;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   target = argv[i++];
   linkname = resolve_win_path (argv[i++]);
   if (linkname == NULL) return -1;
@@ -6729,12 +6994,13 @@
   int r;
   const char *target;
   char *linkname;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   target = argv[i++];
   linkname = resolve_win_path (argv[i++]);
   if (linkname == NULL) return -1;
@@ -6747,12 +7013,13 @@
 {
   char *r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_readlink (g, path);
@@ -6768,12 +7035,13 @@
   int r;
   char *path;
   int len;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   {
@@ -6804,12 +7072,13 @@
 {
   int r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_swapon_device (g, device);
   return r;
@@ -6819,12 +7088,13 @@
 {
   int r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_swapoff_device (g, device);
   return r;
@@ -6834,12 +7104,13 @@
 {
   int r;
   char *file;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   file = resolve_win_path (argv[i++]);
   if (file == NULL) return -1;
   r = guestfs_swapon_file (g, file);
@@ -6851,12 +7122,13 @@
 {
   int r;
   char *file;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   file = resolve_win_path (argv[i++]);
   if (file == NULL) return -1;
   r = guestfs_swapoff_file (g, file);
@@ -6868,12 +7140,13 @@
 {
   int r;
   const char *label;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   label = argv[i++];
   r = guestfs_swapon_label (g, label);
   return r;
@@ -6883,12 +7156,13 @@
 {
   int r;
   const char *label;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   label = argv[i++];
   r = guestfs_swapoff_label (g, label);
   return r;
@@ -6898,12 +7172,13 @@
 {
   int r;
   const char *uuid;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   uuid = argv[i++];
   r = guestfs_swapon_uuid (g, uuid);
   return r;
@@ -6913,12 +7188,13 @@
 {
   int r;
   const char *uuid;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   uuid = argv[i++];
   r = guestfs_swapoff_uuid (g, uuid);
   return r;
@@ -6928,12 +7204,13 @@
 {
   int r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_mkswap_file (g, path);
@@ -6945,12 +7222,13 @@
 {
   int r;
   int maxevents;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   {
     strtol_error xerr;
     long long r;
@@ -6979,12 +7257,13 @@
   int64_t r;
   char *path;
   int mask;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   {
@@ -7017,12 +7296,13 @@
 {
   int r;
   int wd;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   {
     strtol_error xerr;
     long long r;
@@ -7049,6 +7329,7 @@
 static int run_inotify_read (const char *cmd, size_t argc, char *argv[])
 {
   struct guestfs_inotify_event_list *r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -7064,6 +7345,7 @@
 static int run_inotify_files (const char *cmd, size_t argc, char *argv[])
 {
   char **r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -7079,6 +7361,7 @@
 static int run_inotify_close (const char *cmd, size_t argc, char *argv[])
 {
   int r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -7092,12 +7375,13 @@
 {
   int r;
   const char *context;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   context = argv[i++];
   r = guestfs_setcon (g, context);
   return r;
@@ -7106,6 +7390,7 @@
 static int run_getcon (const char *cmd, size_t argc, char *argv[])
 {
   char *r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -7124,12 +7409,13 @@
   const char *fstype;
   int blocksize;
   const char *device;
+  size_t i = 0;
+
   if (argc != 3) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 3);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   fstype = argv[i++];
   {
     strtol_error xerr;
@@ -7160,12 +7446,13 @@
   int r;
   int blocksize;
   const char *device;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   {
     strtol_error xerr;
     long long r;
@@ -7196,12 +7483,13 @@
   int blocksize;
   const char *label;
   const char *device;
+  size_t i = 0;
+
   if (argc != 3) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 3);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   {
     strtol_error xerr;
     long long r;
@@ -7233,12 +7521,13 @@
   int blocksize;
   const char *uuid;
   const char *device;
+  size_t i = 0;
+
   if (argc != 3) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 3);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   {
     strtol_error xerr;
     long long r;
@@ -7271,12 +7560,13 @@
   int blocksize;
   const char *device;
   const char *journal;
+  size_t i = 0;
+
   if (argc != 4) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 4);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   fstype = argv[i++];
   {
     strtol_error xerr;
@@ -7310,12 +7600,13 @@
   int blocksize;
   const char *device;
   const char *label;
+  size_t i = 0;
+
   if (argc != 4) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 4);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   fstype = argv[i++];
   {
     strtol_error xerr;
@@ -7349,12 +7640,13 @@
   int blocksize;
   const char *device;
   const char *uuid;
+  size_t i = 0;
+
   if (argc != 4) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 4);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   fstype = argv[i++];
   {
     strtol_error xerr;
@@ -7385,12 +7677,13 @@
 {
   int r;
   const char *modulename;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   modulename = argv[i++];
   r = guestfs_modprobe (g, modulename);
   return r;
@@ -7400,12 +7693,13 @@
 {
   char *r;
   char **words;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   words = parse_string_list (argv[i++]);
   if (words == NULL) return -1;
   r = guestfs_echo_daemon (g, words);
@@ -7421,12 +7715,13 @@
   int r;
   char *directory;
   char *files;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   directory = resolve_win_path (argv[i++]);
   if (directory == NULL) return -1;
   files = file_out (argv[i++]);
@@ -7441,12 +7736,13 @@
 {
   char *r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_case_sensitive_path (g, path);
@@ -7461,12 +7757,13 @@
 {
   char *r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_vfs_type (g, device);
   if (r == NULL) return -1;
@@ -7479,12 +7776,13 @@
 {
   int r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_truncate (g, path);
@@ -7497,12 +7795,13 @@
   int r;
   char *path;
   int64_t size;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   {
@@ -7531,12 +7830,13 @@
   int64_t atnsecs;
   int64_t mtsecs;
   int64_t mtnsecs;
+  size_t i = 0;
+
   if (argc != 5) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 5);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   {
@@ -7601,12 +7901,13 @@
   int r;
   char *path;
   int mode;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   {
@@ -7639,12 +7940,13 @@
   int owner;
   int group;
   char *path;
+  size_t i = 0;
+
   if (argc != 3) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 3);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   {
     strtol_error xerr;
     long long r;
@@ -7695,12 +7997,13 @@
   struct guestfs_stat_list *r;
   char *path;
   char **names;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   names = parse_string_list (argv[i++]);
@@ -7719,12 +8022,13 @@
   struct guestfs_xattr_list *r;
   char *path;
   char **names;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   names = parse_string_list (argv[i++]);
@@ -7743,12 +8047,13 @@
   char **r;
   char *path;
   char **names;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   names = parse_string_list (argv[i++]);
@@ -7769,12 +8074,13 @@
   char *path;
   int count;
   int64_t offset;
+  size_t i = 0;
+
   if (argc != 3) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 3);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   {
@@ -7826,12 +8132,13 @@
   int r;
   const char *device;
   const char *parttype;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   parttype = argv[i++];
   r = guestfs_part_init (g, device, parttype);
@@ -7845,12 +8152,13 @@
   const char *prlogex;
   int64_t startsect;
   int64_t endsect;
+  size_t i = 0;
+
   if (argc != 4) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 4);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   prlogex = argv[i++];
   {
@@ -7888,12 +8196,13 @@
   int r;
   const char *device;
   const char *parttype;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   parttype = argv[i++];
   r = guestfs_part_disk (g, device, parttype);
@@ -7906,12 +8215,13 @@
   const char *device;
   int partnum;
   int bootable;
+  size_t i = 0;
+
   if (argc != 3) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 3);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   {
     strtol_error xerr;
@@ -7943,12 +8253,13 @@
   const char *device;
   int partnum;
   const char *name;
+  size_t i = 0;
+
   if (argc != 3) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 3);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   {
     strtol_error xerr;
@@ -7978,12 +8289,13 @@
 {
   struct guestfs_partition_list *r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_part_list (g, device);
   if (r == NULL) return -1;
@@ -7996,12 +8308,13 @@
 {
   char *r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_part_get_parttype (g, device);
   if (r == NULL) return -1;
@@ -8016,12 +8329,13 @@
   int c;
   int len;
   char *path;
+  size_t i = 0;
+
   if (argc != 3) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 3);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   {
     strtol_error xerr;
     long long r;
@@ -8071,12 +8385,13 @@
 {
   int r;
   char **groups;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   groups = parse_string_list (argv[i++]);
   if (groups == NULL) return -1;
   r = guestfs_available (g, groups);
@@ -8089,12 +8404,13 @@
   int r;
   char *src;
   char *dest;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   src = resolve_win_path (argv[i++]);
   if (src == NULL) return -1;
   dest = resolve_win_path (argv[i++]);
@@ -8109,12 +8425,13 @@
 {
   int64_t r;
   char *file;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   file = resolve_win_path (argv[i++]);
   if (file == NULL) return -1;
   r = guestfs_filesize (g, file);
@@ -8129,12 +8446,13 @@
   int r;
   const char *logvol;
   const char *newlogvol;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   logvol = argv[i++];
   newlogvol = argv[i++];
   r = guestfs_lvrename (g, logvol, newlogvol);
@@ -8146,12 +8464,13 @@
   int r;
   const char *volgroup;
   const char *newvolgroup;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   volgroup = argv[i++];
   newvolgroup = argv[i++];
   r = guestfs_vgrename (g, volgroup, newvolgroup);
@@ -8164,12 +8483,13 @@
   size_t size;
   char *initrdpath;
   const char *filename;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   initrdpath = resolve_win_path (argv[i++]);
   if (initrdpath == NULL) return -1;
   filename = argv[i++];
@@ -8189,12 +8509,13 @@
 {
   char *r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_pvuuid (g, device);
   if (r == NULL) return -1;
@@ -8207,12 +8528,13 @@
 {
   char *r;
   const char *vgname;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   vgname = argv[i++];
   r = guestfs_vguuid (g, vgname);
   if (r == NULL) return -1;
@@ -8225,12 +8547,13 @@
 {
   char *r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_lvuuid (g, device);
   if (r == NULL) return -1;
@@ -8243,12 +8566,13 @@
 {
   char **r;
   const char *vgname;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   vgname = argv[i++];
   r = guestfs_vgpvuuids (g, vgname);
   if (r == NULL) return -1;
@@ -8261,12 +8585,13 @@
 {
   char **r;
   const char *vgname;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   vgname = argv[i++];
   r = guestfs_vglvuuids (g, vgname);
   if (r == NULL) return -1;
@@ -8281,12 +8606,13 @@
   char *src;
   char *dest;
   int64_t size;
+  size_t i = 0;
+
   if (argc != 3) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 3);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   src = resolve_win_path (argv[i++]);
   if (src == NULL) return -1;
   dest = resolve_win_path (argv[i++]);
@@ -8314,12 +8640,13 @@
 {
   int r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_zero_device (g, device);
   return r;
@@ -8330,12 +8657,13 @@
   int r;
   char *tarball;
   char *directory;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   tarball = file_in (argv[i++]);
   if (tarball == NULL) return -1;
   directory = resolve_win_path (argv[i++]);
@@ -8351,12 +8679,13 @@
   int r;
   char *directory;
   char *tarball;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   directory = resolve_win_path (argv[i++]);
   if (directory == NULL) return -1;
   tarball = file_out (argv[i++]);
@@ -8371,12 +8700,13 @@
 {
   int r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_ntfsresize (g, device);
   return r;
@@ -8385,6 +8715,7 @@
 static int run_vgscan (const char *cmd, size_t argc, char *argv[])
 {
   int r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -8399,12 +8730,13 @@
   int r;
   const char *device;
   int partnum;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   {
     strtol_error xerr;
@@ -8434,12 +8766,13 @@
   int r;
   const char *device;
   int partnum;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   {
     strtol_error xerr;
@@ -8471,12 +8804,13 @@
   int r;
   const char *device;
   int partnum;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   {
     strtol_error xerr;
@@ -8509,12 +8843,13 @@
   const char *device;
   int partnum;
   int idbyte;
+  size_t i = 0;
+
   if (argc != 3) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 3);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   {
     strtol_error xerr;
@@ -8563,12 +8898,13 @@
   char *r;
   const char *csumtype;
   const char *device;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   csumtype = argv[i++];
   device = argv[i++];
   r = guestfs_checksum_device (g, csumtype, device);
@@ -8583,12 +8919,13 @@
   int r;
   const char *lv;
   int percent;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   lv = argv[i++];
   {
     strtol_error xerr;
@@ -8617,12 +8954,13 @@
 {
   int r;
   const char *augpath;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   augpath = argv[i++];
   r = guestfs_aug_clear (g, augpath);
   return r;
@@ -8631,6 +8969,7 @@
 static int run_get_umask (const char *cmd, size_t argc, char *argv[])
 {
   int r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -8648,12 +8987,13 @@
   char *filename;
   const char *tmpname;
   int mode;
+  size_t i = 0;
+
   if (argc != 3) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 3);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   filename = file_in (argv[i++]);
   if (filename == NULL) return -1;
   tmpname = argv[i++];
@@ -8686,12 +9026,13 @@
   int r;
   char *base64file;
   char *filename;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   base64file = file_in (argv[i++]);
   if (base64file == NULL) return -1;
   filename = resolve_win_path (argv[i++]);
@@ -8707,12 +9048,13 @@
   int r;
   char *filename;
   char *base64file;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   filename = resolve_win_path (argv[i++]);
   if (filename == NULL) return -1;
   base64file = file_out (argv[i++]);
@@ -8729,12 +9071,13 @@
   const char *csumtype;
   char *directory;
   char *sumsfile;
+  size_t i = 0;
+
   if (argc != 3) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 3);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   csumtype = argv[i++];
   directory = resolve_win_path (argv[i++]);
   if (directory == NULL) return -1;
@@ -8752,12 +9095,13 @@
   const char *pattern;
   int len;
   char *path;
+  size_t i = 0;
+
   if (argc != 3) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 3);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   pattern = argv[i++];
   {
     strtol_error xerr;
@@ -8791,12 +9135,13 @@
   char *path;
   const char *content;
   size_t content_size;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   content = argv[i];
@@ -8814,12 +9159,13 @@
   const char *content;
   size_t content_size;
   int64_t offset;
+  size_t i = 0;
+
   if (argc != 3) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 3);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   content = argv[i];
@@ -8850,12 +9196,13 @@
   int r;
   const char *device;
   int64_t size;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   {
     strtol_error xerr;
@@ -8879,12 +9226,13 @@
   int r;
   const char *device;
   int64_t size;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   {
     strtol_error xerr;
@@ -8908,12 +9256,13 @@
   int r;
   const char *device;
   int64_t size;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   {
     strtol_error xerr;
@@ -8935,6 +9284,7 @@
 static int run_available_all_groups (const char *cmd, size_t argc, char *argv[])
 {
   char **r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -8952,12 +9302,13 @@
   int r;
   char *path;
   int64_t len;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   {
@@ -8982,12 +9333,13 @@
 {
   char *r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_vfs_label (g, device);
   if (r == NULL) return -1;
@@ -9000,12 +9352,13 @@
 {
   char *r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_vfs_uuid (g, device);
   if (r == NULL) return -1;
@@ -9018,12 +9371,13 @@
 {
   int r;
   char **devices;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   devices = parse_string_list (argv[i++]);
   if (devices == NULL) return -1;
   r = guestfs_lvm_set_filter (g, devices);
@@ -9034,6 +9388,7 @@
 static int run_lvm_clear_filter (const char *cmd, size_t argc, char *argv[])
 {
   int r;
+
   if (argc != 0) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 0);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
@@ -9049,12 +9404,13 @@
   const char *device;
   char *key;
   const char *mapname;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   key = read_key ("key");
   if (key == NULL) return -1;
@@ -9070,12 +9426,13 @@
   const char *device;
   char *key;
   const char *mapname;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   key = read_key ("key");
   if (key == NULL) return -1;
@@ -9089,12 +9446,13 @@
 {
   int r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_luks_close (g, device);
   return r;
@@ -9106,12 +9464,13 @@
   const char *device;
   char *key;
   int keyslot;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   key = read_key ("key");
   if (key == NULL) return -1;
@@ -9146,12 +9505,13 @@
   char *key;
   int keyslot;
   const char *cipher;
+  size_t i = 0;
+
   if (argc != 3) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 3);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   key = read_key ("key");
   if (key == NULL) return -1;
@@ -9187,12 +9547,13 @@
   char *key;
   char *newkey;
   int keyslot;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   key = read_key ("key");
   if (key == NULL) return -1;
@@ -9229,12 +9590,13 @@
   const char *device;
   char *key;
   int keyslot;
+  size_t i = 0;
+
   if (argc != 2) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 2);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   key = read_key ("key");
   if (key == NULL) return -1;
@@ -9266,12 +9628,13 @@
 {
   int r;
   const char *device;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   r = guestfs_is_lv (g, device);
   if (r == -1) return -1;
@@ -9283,12 +9646,13 @@
 {
   char *r;
   const char *uuid;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   uuid = argv[i++];
   r = guestfs_findfs_uuid (g, uuid);
   if (r == NULL) return -1;
@@ -9301,12 +9665,13 @@
 {
   char *r;
   const char *label;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   label = argv[i++];
   r = guestfs_findfs_label (g, label);
   if (r == NULL) return -1;
@@ -9319,12 +9684,13 @@
 {
   int r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_is_chardev (g, path);
@@ -9338,12 +9704,13 @@
 {
   int r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_is_blockdev (g, path);
@@ -9357,12 +9724,13 @@
 {
   int r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_is_fifo (g, path);
@@ -9376,12 +9744,13 @@
 {
   int r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_is_symlink (g, path);
@@ -9395,12 +9764,13 @@
 {
   int r;
   char *path;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   path = resolve_win_path (argv[i++]);
   if (path == NULL) return -1;
   r = guestfs_is_socket (g, path);
@@ -9414,12 +9784,13 @@
 {
   char *r;
   const char *partition;
+  size_t i = 0;
+
   if (argc != 1) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 1);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   partition = argv[i++];
   r = guestfs_part_to_dev (g, partition);
   if (r == NULL) return -1;
@@ -9434,12 +9805,13 @@
   char *filename;
   char *remotefilename;
   int64_t offset;
+  size_t i = 0;
+
   if (argc != 3) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 3);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   filename = file_in (argv[i++]);
   if (filename == NULL) return -1;
   remotefilename = resolve_win_path (argv[i++]);
@@ -9470,12 +9842,13 @@
   char *filename;
   int64_t offset;
   int64_t size;
+  size_t i = 0;
+
   if (argc != 4) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 4);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   remotefilename = resolve_win_path (argv[i++]);
   if (remotefilename == NULL) return -1;
   filename = file_out (argv[i++]);
@@ -9519,12 +9892,13 @@
   const char *content;
   size_t content_size;
   int64_t offset;
+  size_t i = 0;
+
   if (argc != 3) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 3);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   content = argv[i];
   content_size = strlen (argv[i]);
@@ -9555,12 +9929,13 @@
   const char *device;
   int count;
   int64_t offset;
+  size_t i = 0;
+
   if (argc != 3) {
     fprintf (stderr, _("%s should have %d parameter(s)\n"), cmd, 3);
     fprintf (stderr, _("type 'help %s' for help on %s\n"), cmd, cmd);
     return -1;
   }
-  size_t i = 0;
   device = argv[i++];
   {
     strtol_error xerr;
@@ -9607,12 +9982,15 @@
 
 int run_action (const char *cmd, size_t argc, char *argv[])
 {
-  if (STRCASEEQ (cmd, "add_cdrom") || STRCASEEQ (cmd, "add-cdrom") || STRCASEEQ (cmd, "cdrom"))
+  if (STRCASEEQ (cmd, "add_cdrom") || STRCASEEQ (cmd, "add-cdrom"))
     return run_add_cdrom (cmd, argc, argv);
   else
-  if (STRCASEEQ (cmd, "add_drive") || STRCASEEQ (cmd, "add-drive") || STRCASEEQ (cmd, "add"))
+  if (STRCASEEQ (cmd, "add_drive") || STRCASEEQ (cmd, "add-drive"))
     return run_add_drive (cmd, argc, argv);
   else
+  if (STRCASEEQ (cmd, "add_drive_opts") || STRCASEEQ (cmd, "add-drive-opts") || STRCASEEQ (cmd, "add"))
+    return run_add_drive_opts (cmd, argc, argv);
+  else
   if (STRCASEEQ (cmd, "add_drive_ro") || STRCASEEQ (cmd, "add-drive-ro") || STRCASEEQ (cmd, "add-ro"))
     return run_add_drive_ro (cmd, argc, argv);
   else
diff -ur v1/fish/completion.c v2/fish/completion.c
--- v1/fish/completion.c	2010-10-22 16:40:45.672969169 +0100
+++ v2/fish/completion.c	2010-10-21 10:38:35.318935013 +0100
@@ -40,9 +40,7 @@
   "run",
   "kill-subprocess",
   "add-drive",
-  "add",
   "add-cdrom",
-  "cdrom",
   "add-drive-ro",
   "add-ro",
   "config",
@@ -100,6 +98,8 @@
   "network",
   "get-network",
   "list-filesystems",
+  "add-drive-opts",
+  "add",
   "mount",
   "sync",
   "touch",
diff -ur v1/fish/guestfish-actions.pod v2/fish/guestfish-actions.pod
--- v1/fish/guestfish-actions.pod	2010-10-22 16:40:45.712971413 +0100
+++ v2/fish/guestfish-actions.pod	2010-10-21 10:38:35.395939242 +0100
@@ -1,7 +1,5 @@
 =head2 add-cdrom
 
-=head2 cdrom
-
  add-cdrom filename
 
 This function adds a virtual CD-ROM disk image to the guest.
@@ -27,15 +25,37 @@
 
 =back
 
+This function is deprecated.
+In new code, use the C<add_drive_opts> call instead.
+
+Deprecated functions will not be removed from the API, but the
+fact that they are deprecated indicates that there are problems
+with correct use of these functions.
+
 =head2 add-drive
 
+ add-drive filename
+
+This function is the equivalent of calling L</add-drive-opts>
+with no optional parameters, so the disk is added writable, with
+the format being detected automatically.
+
+Automatic detection of the format opens you up to a potential
+security hole when dealing with untrusted raw-format images.
+See CVE-2010-3851 and RHBZ#642934.  Specifying the format closes
+this security hole.  Therefore you should think about replacing
+calls to this function with calls to L</add-drive-opts>,
+and specifying the format.
+
+=head2 add-drive-opts
+
 =head2 add
 
- add-drive filename
+ add-drive-opts filename [readonly:..] [format:..] [iface:..]
 
-This function adds a virtual machine disk image C<filename> to the
-guest.  The first time you call this function, the disk appears as IDE
-disk 0 (C</dev/sda>) in the guest, the second time as C</dev/sdb>, and
+This function adds a virtual machine disk image C<filename> to
+libguestfs.  The first time you call this function, the disk
+appears as C</dev/sda>, the second time as C</dev/sdb>, and
 so on.
 
 You don't necessarily need to be root when using libguestfs.  However
@@ -44,21 +64,37 @@
 just want to read the image or write access if you want to modify the
 image).
 
-This is equivalent to the qemu parameter
-C<-drive file=filename,cache=off,if=...>.
+This call checks that C<filename> exists.
 
-C<cache=off> is omitted in cases where it is not supported by
-the underlying filesystem.
+The optional arguments are:
 
-C<if=...> is set at compile time by the configuration option
-C<./configure --with-drive-if=...>.  In the rare case where you
-might need to change this at run time, use L</add-drive-with-if>
-or L</add-drive-ro-with-if>.
+=over 4
 
-Note that this call checks for the existence of C<filename>.  This
-stops you from specifying other types of drive which are supported
-by qemu such as C<nbd:> and C<http:> URLs.  To specify those, use
-the general L</config> call instead.
+=item C<readonly>
+
+If true then the image is treated as read-only.  Writes are still
+allowed, but they are stored in a temporary snapshot overlay which
+is discarded at the end.  The disk that you add is not modified.
+
+=item C<format>
+
+This forces the image format.  If you omit this (or use L</add-drive>
+or L</add-drive-ro>) then the format is automatically detected.
+Possible formats include C<raw> and C<qcow2>.
+
+Automatic detection of the format opens you up to a potential
+security hole when dealing with untrusted raw-format images.
+See CVE-2010-3851 and RHBZ#642934.  Specifying the format closes
+this security hole.
+
+=item C<iface>
+
+This rarely-used option lets you emulate the behaviour of the
+deprecated L</add-drive-with-if> call (q.v.)
+
+=back
+
+This command has one or more optional arguments.  See L</OPTIONAL ARGUMENTS>.
 
 =head2 add-drive-ro
 
@@ -66,27 +102,10 @@
 
  add-drive-ro filename
 
-This adds a drive in snapshot mode, making it effectively
-read-only.
-
-Note that writes to the device are allowed, and will be seen for
-the duration of the guestfs handle, but they are written
-to a temporary file which is discarded as soon as the guestfs
-handle is closed.  We don't currently have any method to enable
-changes to be committed, although qemu can support this.
-
-This is equivalent to the qemu parameter
-C<-drive file=filename,snapshot=on,if=...>.
-
-C<if=...> is set at compile time by the configuration option
-C<./configure --with-drive-if=...>.  In the rare case where you
-might need to change this at run time, use L</add-drive-with-if>
-or L</add-drive-ro-with-if>.
-
-Note that this call checks for the existence of C<filename>.  This
-stops you from specifying other types of drive which are supported
-by qemu such as C<nbd:> and C<http:> URLs.  To specify those, use
-the general L</config> call instead.
+This function is the equivalent of calling L</add-drive-opts>
+with the optional parameter C<GUESTFS_ADD_DRIVE_OPTS_READONLY> set to 1,
+so the disk is added read-only, with the format being detected
+automatically.
 
 =head2 add-drive-ro-with-if
 
@@ -95,6 +114,13 @@
 This is the same as L</add-drive-ro> but it allows you
 to specify the QEMU interface emulation to use at run time.
 
+This function is deprecated.
+In new code, use the C<add_drive_opts> call instead.
+
+Deprecated functions will not be removed from the API, but the
+fact that they are deprecated indicates that there are problems
+with correct use of these functions.
+
 =head2 add-drive-with-if
 
  add-drive-with-if filename iface
@@ -102,6 +128,13 @@
 This is the same as L</add-drive> but it allows you
 to specify the QEMU interface emulation to use at run time.
 
+This function is deprecated.
+In new code, use the C<add_drive_opts> call instead.
+
+Deprecated functions will not be removed from the API, but the
+fact that they are deprecated indicates that there are problems
+with correct use of these functions.
+
 =head2 aug-clear
 
  aug-clear augpath
diff -ur v1/java/com/redhat/et/libguestfs/GuestFS.java v2/java/com/redhat/et/libguestfs/GuestFS.java
--- v1/java/com/redhat/et/libguestfs/GuestFS.java	2010-10-22 16:40:46.331006072 +0100
+++ v2/java/com/redhat/et/libguestfs/GuestFS.java	2010-10-21 17:48:25.307121383 +0100
@@ -361,34 +361,18 @@
   /**
    * add an image to examine or modify
    * <p>
-   * This function adds a virtual machine disk image
-   * "filename" to the guest. The first time you call this
-   * function, the disk appears as IDE disk 0 ("/dev/sda") in
-   * the guest, the second time as "/dev/sdb", and so on.
-   * <p>
-   * You don't necessarily need to be root when using
-   * libguestfs. However you obviously do need sufficient
-   * permissions to access the filename for whatever
-   * operations you want to perform (ie. read access if you
-   * just want to read the image or write access if you want
-   * to modify the image).
-   * <p>
-   * This is equivalent to the qemu parameter "-drive
-   * file=filename,cache=off,if=...".
-   * <p>
-   * "cache=off" is omitted in cases where it is not
-   * supported by the underlying filesystem.
+   * This function is the equivalent of calling
+   * "g.add_drive_opts" with no optional parameters, so the
+   * disk is added writable, with the format being detected
+   * automatically.
    * <p>
-   * "if=..." is set at compile time by the configuration
-   * option "./configure --with-drive-if=...". In the rare
-   * case where you might need to change this at run time,
-   * use "g.add_drive_with_if" or "g.add_drive_ro_with_if".
-   * <p>
-   * Note that this call checks for the existence of
-   * "filename". This stops you from specifying other types
-   * of drive which are supported by qemu such as "nbd:" and
-   * "http:" URLs. To specify those, use the general
-   * "g.config" call instead.
+   * Automatic detection of the format opens you up to a
+   * potential security hole when dealing with untrusted
+   * raw-format images. See CVE-2010-3851 and RHBZ#642934.
+   * Specifying the format closes this security hole.
+   * Therefore you should think about replacing calls to this
+   * function with calls to "g.add_drive_opts", and
+   * specifying the format.
    * <p>
    * @throws LibGuestFSException
    */
@@ -424,6 +408,13 @@
    * into the guest), then you should probably use
    * "g.add_drive_ro" instead.
    * <p>
+   * This function is deprecated. In new code, use the
+   * "add_drive_opts" call instead.
+   * <p>
+   * Deprecated functions will not be removed from the API,
+   * but the fact that they are deprecated indicates that
+   * there are problems with correct use of these functions.
+   * <p>
    * @throws LibGuestFSException
    */
   public void add_cdrom (String filename)
@@ -439,29 +430,11 @@
   /**
    * add a drive in snapshot mode (read-only)
    * <p>
-   * This adds a drive in snapshot mode, making it
-   * effectively read-only.
-   * <p>
-   * Note that writes to the device are allowed, and will be
-   * seen for the duration of the guestfs handle, but they
-   * are written to a temporary file which is discarded as
-   * soon as the guestfs handle is closed. We don't currently
-   * have any method to enable changes to be committed,
-   * although qemu can support this.
-   * <p>
-   * This is equivalent to the qemu parameter "-drive
-   * file=filename,snapshot=on,if=...".
-   * <p>
-   * "if=..." is set at compile time by the configuration
-   * option "./configure --with-drive-if=...". In the rare
-   * case where you might need to change this at run time,
-   * use "g.add_drive_with_if" or "g.add_drive_ro_with_if".
-   * <p>
-   * Note that this call checks for the existence of
-   * "filename". This stops you from specifying other types
-   * of drive which are supported by qemu such as "nbd:" and
-   * "http:" URLs. To specify those, use the general
-   * "g.config" call instead.
+   * This function is the equivalent of calling
+   * "g.add_drive_opts" with the optional parameter
+   * "GUESTFS_ADD_DRIVE_OPTS_READONLY" set to 1, so the disk
+   * is added read-only, with the format being detected
+   * automatically.
    * <p>
    * @throws LibGuestFSException
    */
@@ -1132,6 +1105,13 @@
    * This is the same as "g.add_drive" but it allows you to
    * specify the QEMU interface emulation to use at run time.
    * <p>
+   * This function is deprecated. In new code, use the
+   * "add_drive_opts" call instead.
+   * <p>
+   * Deprecated functions will not be removed from the API,
+   * but the fact that they are deprecated indicates that
+   * there are problems with correct use of these functions.
+   * <p>
    * @throws LibGuestFSException
    */
   public void add_drive_with_if (String filename, String iface)
@@ -1151,6 +1131,13 @@
    * to specify the QEMU interface emulation to use at run
    * time.
    * <p>
+   * This function is deprecated. In new code, use the
+   * "add_drive_opts" call instead.
+   * <p>
+   * Deprecated functions will not be removed from the API,
+   * but the fact that they are deprecated indicates that
+   * there are problems with correct use of these functions.
+   * <p>
    * @throws LibGuestFSException
    */
   public void add_drive_ro_with_if (String filename, String iface)
@@ -1647,6 +1634,65 @@
     throws LibGuestFSException;
 
   /**
+   * add an image to examine or modify
+   * <p>
+   * This function adds a virtual machine disk image
+   * "filename" to libguestfs. The first time you call this
+   * function, the disk appears as "/dev/sda", the second
+   * time as "/dev/sdb", and so on.
+   * <p>
+   * You don't necessarily need to be root when using
+   * libguestfs. However you obviously do need sufficient
+   * permissions to access the filename for whatever
+   * operations you want to perform (ie. read access if you
+   * just want to read the image or write access if you want
+   * to modify the image).
+   * <p>
+   * This call checks that "filename" exists.
+   * <p>
+   * The optional arguments are:
+   * <p>
+   * "readonly"
+   * If true then the image is treated as read-only.
+   * Writes are still allowed, but they are stored in a
+   * temporary snapshot overlay which is discarded at the
+   * end. The disk that you add is not modified.
+   * <p>
+   * "format"
+   * This forces the image format. If you omit this (or
+   * use "g.add_drive" or "g.add_drive_ro") then the
+   * format is automatically detected. Possible formats
+   * include "raw" and "qcow2".
+   * <p>
+   * Automatic detection of the format opens you up to a
+   * potential security hole when dealing with untrusted
+   * raw-format images. See CVE-2010-3851 and
+   * RHBZ#642934. Specifying the format closes this
+   * security hole.
+   * <p>
+   * "iface"
+   * This rarely-used option lets you emulate the
+   * behaviour of the deprecated "g.add_drive_with_if"
+   * call (q.v.)
+   * <p>
+   * Optional arguments are supplied in the final
+   * Map<String,Object> parameter, which is a hash of the
+   * argument name to its value (cast to Object). Pass an
+   * empty Map for no optional arguments.
+   * <p>
+   * @throws LibGuestFSException
+   */
+  public void add_drive_opts (String filename, HashMap optargs)
+    throws LibGuestFSException
+  {
+    if (g == 0)
+      throw new LibGuestFSException ("add_drive_opts: handle is closed");
+    _add_drive_opts (g, filename, optargs);
+  }
+  private native void _add_drive_opts (long g, String filename, HashMap optargs)
+    throws LibGuestFSException;
+
+  /**
    * mount a guest disk at a position in the filesystem
    * <p>
    * Mount a guest disk at a position in the filesystem.
diff -ur v1/java/com_redhat_et_libguestfs_GuestFS.c v2/java/com_redhat_et_libguestfs_GuestFS.c
--- v1/java/com_redhat_et_libguestfs_GuestFS.c	2010-10-22 16:40:46.518016561 +0100
+++ v2/java/com_redhat_et_libguestfs_GuestFS.c	2010-10-21 17:50:25.307859189 +0100
@@ -1511,6 +1511,27 @@
 }
 
 JNIEXPORT void JNICALL
+Java_com_redhat_et_libguestfs_GuestFS__1add_1drive_1opts
+  (JNIEnv *env, jobject obj, jlong jg, jstring jfilename, jobject joptargs)
+{
+  guestfs_h *g = (guestfs_h *) (long) jg;
+  int r;
+  const char *filename;
+
+  filename = (*env)->GetStringUTFChars (env, jfilename, NULL);
+  throw_exception (env, "add_drive_opts: internal error: please let us know how to read a Java HashMap parameter from JNI bindings!");
+  return NULL;
+  /*
+  r = guestfs_add_drive_opts_argv (g, filename, optargs);
+  (*env)->ReleaseStringUTFChars (env, jfilename, filename);
+  if (r == -1) {
+    throw_exception (env, guestfs_last_error (g));
+    return ;
+  }
+  */
+}
+
+JNIEXPORT void JNICALL
 Java_com_redhat_et_libguestfs_GuestFS__1mount
   (JNIEnv *env, jobject obj, jlong jg, jstring jdevice, jstring jmountpoint)
 {
diff -ur v1/ocaml/guestfs_c_actions.c v2/ocaml/guestfs_c_actions.c
--- v1/ocaml/guestfs_c_actions.c	2010-10-22 16:40:45.889981339 +0100
+++ v2/ocaml/guestfs_c_actions.c	2010-10-21 12:32:42.781460642 +0100
@@ -586,6 +586,55 @@
 }
 
 /* Automatically generated wrapper for function
+ * val add_drive_opts : t -> ?readonly:bool -> ?format:string -> ?iface:string -> string -> unit
+ */
+
+/* Emit prototype to appease gcc's -Wmissing-prototypes. */
+CAMLprim value ocaml_guestfs_add_drive_opts (value gv, value readonlyv, value formatv, value ifacev, value filenamev);
+
+CAMLprim value
+ocaml_guestfs_add_drive_opts (value gv, value readonlyv, value formatv, value ifacev, value filenamev)
+{
+  CAMLparam5 (gv, readonlyv, formatv, ifacev, filenamev);
+  CAMLlocal1 (rv);
+
+  guestfs_h *g = Guestfs_val (gv);
+  if (g == NULL)
+    ocaml_guestfs_raise_closed ("add_drive_opts");
+
+  char *filename = guestfs_safe_strdup (g, String_val (filenamev));
+  struct guestfs_add_drive_opts_argv optargs_s = { .bitmask = 0 };
+  struct guestfs_add_drive_opts_argv *optargs = &optargs_s;
+  if (readonlyv != Val_int (0)) {
+    optargs_s.bitmask |= GUESTFS_ADD_DRIVE_OPTS_READONLY_BITMASK;
+    optargs_s.readonly = Bool_val (Field (readonlyv, 0));
+  }
+  if (formatv != Val_int (0)) {
+    optargs_s.bitmask |= GUESTFS_ADD_DRIVE_OPTS_FORMAT_BITMASK;
+    optargs_s.format = guestfs_safe_strdup (g, String_val (Field (formatv, 0)));
+  }
+  if (ifacev != Val_int (0)) {
+    optargs_s.bitmask |= GUESTFS_ADD_DRIVE_OPTS_IFACE_BITMASK;
+    optargs_s.iface = guestfs_safe_strdup (g, String_val (Field (ifacev, 0)));
+  }
+  int r;
+
+  caml_enter_blocking_section ();
+  r = guestfs_add_drive_opts_argv (g, filename, optargs);
+  caml_leave_blocking_section ();
+  free (filename);
+  if (formatv != Val_int (0))
+    free ((char *) optargs_s.format);
+  if (ifacev != Val_int (0))
+    free ((char *) optargs_s.iface);
+  if (r == -1)
+    ocaml_guestfs_raise_error (g, "add_drive_opts");
+
+  rv = Val_unit;
+  CAMLreturn (rv);
+}
+
+/* Automatically generated wrapper for function
  * val add_drive_ro : t -> string -> unit
  */
 
diff -ur v1/ocaml/guestfs.ml v2/ocaml/guestfs.ml
--- v1/ocaml/guestfs.ml	2010-10-22 16:40:45.792975900 +0100
+++ v2/ocaml/guestfs.ml	2010-10-21 12:13:38.158738846 +0100
@@ -167,6 +167,7 @@
 
 external add_cdrom : t -> string -> unit = "ocaml_guestfs_add_cdrom"
 external add_drive : t -> string -> unit = "ocaml_guestfs_add_drive"
+external add_drive_opts : t -> ?readonly:bool -> ?format:string -> ?iface:string -> string -> unit = "ocaml_guestfs_add_drive_opts"
 external add_drive_ro : t -> string -> unit = "ocaml_guestfs_add_drive_ro"
 external add_drive_ro_with_if : t -> string -> string -> unit = "ocaml_guestfs_add_drive_ro_with_if"
 external add_drive_with_if : t -> string -> string -> unit = "ocaml_guestfs_add_drive_with_if"
@@ -521,6 +522,7 @@
     method ocaml_handle = g
     method add_cdrom = add_cdrom g
     method add_drive = add_drive g
+    method add_drive_opts = add_drive_opts g
     method add_drive_ro = add_drive_ro g
     method add_drive_ro_with_if = add_drive_ro_with_if g
     method add_drive_with_if = add_drive_with_if g
diff -ur v1/ocaml/guestfs.mli v2/ocaml/guestfs.mli
--- v1/ocaml/guestfs.mli	2010-10-22 16:40:45.772974777 +0100
+++ v2/ocaml/guestfs.mli	2010-10-21 22:05:49.566237699 +0100
@@ -199,6 +199,9 @@
 val add_drive : t -> string -> unit
 (** add an image to examine or modify *)
 
+val add_drive_opts : t -> ?readonly:bool -> ?format:string -> ?iface:string -> string -> unit
+(** add an image to examine or modify *)
+
 val add_drive_ro : t -> string -> unit
 (** add a drive in snapshot mode (read-only) *)
 
@@ -1234,8 +1237,8 @@
 (** {2 Object-oriented API}
 
     This is an alternate way of calling the API using an object-oriented
-    style, so you can use [g#add_drive filename] instead of
-    [Guestfs.add_drive g filename].  Apart from the different style,
+    style, so you can use [g#add_drive_opts filename] instead of
+    [Guestfs.add_drive_opts g filename].  Apart from the different style,
     it offers exactly the same functionality.
 
     Calling [new guestfs ()] creates both the object and the handle.
@@ -1257,6 +1260,7 @@
   method ocaml_handle : t
   method add_cdrom : string -> unit
   method add_drive : string -> unit
+  method add_drive_opts : ?readonly:bool -> ?format:string -> ?iface:string -> string -> unit
   method add_drive_ro : string -> unit
   method add_drive_ro_with_if : string -> string -> unit
   method add_drive_with_if : string -> string -> unit
diff -ur v1/perl/Guestfs.xs v2/perl/Guestfs.xs
--- v1/perl/Guestfs.xs	2010-10-22 16:40:45.959985265 +0100
+++ v2/perl/Guestfs.xs	2010-10-21 14:41:12.417637296 +0100
@@ -1229,6 +1229,46 @@
       free (r);
 
 void
+add_drive_opts (g, filename, ...)
+      guestfs_h *g;
+      char *filename;
+PREINIT:
+      int r;
+      struct guestfs_add_drive_opts_argv optargs_s = { .bitmask = 0 };
+      struct guestfs_add_drive_opts_argv *optargs = &optargs_s;
+      size_t items_i;
+ PPCODE:
+      if (((items - 2) & 1) != 0)
+        croak ("expecting an even number of extra parameters");
+      for (items_i = 2; items_i < items; items_i += 2) {
+        uint64_t this_mask;
+        const char *this_arg;
+
+        this_arg = SvPV_nolen (ST (items_i));
+        if (strcmp (this_arg, "readonly") == 0) {
+          optargs_s.readonly = SvIV (ST (items_i+1));
+          this_mask = GUESTFS_ADD_DRIVE_OPTS_READONLY_BITMASK;
+        }
+        else if (strcmp (this_arg, "format") == 0) {
+          optargs_s.format = SvPV_nolen (ST (items_i+1));
+          this_mask = GUESTFS_ADD_DRIVE_OPTS_FORMAT_BITMASK;
+        }
+        else if (strcmp (this_arg, "iface") == 0) {
+          optargs_s.iface = SvPV_nolen (ST (items_i+1));
+          this_mask = GUESTFS_ADD_DRIVE_OPTS_IFACE_BITMASK;
+        }
+        else croak ("unknown optional argument '%s'", this_arg);
+        if (optargs_s.bitmask & this_mask)
+          croak ("optional argument '%s' given twice",
+                 this_arg);
+        optargs_s.bitmask |= this_mask;
+      }
+
+      r = guestfs_add_drive_opts_argv (g, filename, optargs);
+      if (r == -1)
+        croak ("%s", guestfs_last_error (g));
+
+void
 mount (g, device, mountpoint)
       guestfs_h *g;
       char *device;
diff -ur v1/perl/lib/Sys/Guestfs.pm v2/perl/lib/Sys/Guestfs.pm
--- v1/perl/lib/Sys/Guestfs.pm	2010-10-22 16:40:45.987986836 +0100
+++ v2/perl/lib/Sys/Guestfs.pm	2010-10-21 19:23:37.419062016 +0100
@@ -30,9 +30,9 @@
  use Sys::Guestfs;
 
  my $h = Sys::Guestfs->new ();
- $h->add_drive ('guest.img');
+ $h->add_drive_opts ('guest.img', format => 'raw');
  $h->launch ();
- $h->mount ('/dev/sda1', '/');
+ $h->mount_options ('', '/dev/sda1', '/');
  $h->touch ('/hello');
  $h->sync ();
 
@@ -163,11 +163,31 @@
 
 =back
 
+This function is deprecated.
+In new code, use the C<add_drive_opts> call instead.
+
+Deprecated functions will not be removed from the API, but the
+fact that they are deprecated indicates that there are problems
+with correct use of these functions.
+
 =item $h->add_drive ($filename);
 
-This function adds a virtual machine disk image C<filename> to the
-guest.  The first time you call this function, the disk appears as IDE
-disk 0 (C</dev/sda>) in the guest, the second time as C</dev/sdb>, and
+This function is the equivalent of calling C<$h-E<gt>add_drive_opts>
+with no optional parameters, so the disk is added writable, with
+the format being detected automatically.
+
+Automatic detection of the format opens you up to a potential
+security hole when dealing with untrusted raw-format images.
+See CVE-2010-3851 and RHBZ#642934.  Specifying the format closes
+this security hole.  Therefore you should think about replacing
+calls to this function with calls to C<$h-E<gt>add_drive_opts>,
+and specifying the format.
+
+=item $h->add_drive_opts ($filename [, readonly => $readonly] [, format => $format] [, iface => $iface]);
+
+This function adds a virtual machine disk image C<filename> to
+libguestfs.  The first time you call this function, the disk
+appears as C</dev/sda>, the second time as C</dev/sdb>, and
 so on.
 
 You don't necessarily need to be root when using libguestfs.  However
@@ -176,56 +196,67 @@
 just want to read the image or write access if you want to modify the
 image).
 
-This is equivalent to the qemu parameter
-C<-drive file=filename,cache=off,if=...>.
+This call checks that C<filename> exists.
 
-C<cache=off> is omitted in cases where it is not supported by
-the underlying filesystem.
+The optional arguments are:
 
-C<if=...> is set at compile time by the configuration option
-C<./configure --with-drive-if=...>.  In the rare case where you
-might need to change this at run time, use C<$h-E<gt>add_drive_with_if>
-or C<$h-E<gt>add_drive_ro_with_if>.
+=over 4
 
-Note that this call checks for the existence of C<filename>.  This
-stops you from specifying other types of drive which are supported
-by qemu such as C<nbd:> and C<http:> URLs.  To specify those, use
-the general C<$h-E<gt>config> call instead.
+=item C<readonly>
 
-=item $h->add_drive_ro ($filename);
+If true then the image is treated as read-only.  Writes are still
+allowed, but they are stored in a temporary snapshot overlay which
+is discarded at the end.  The disk that you add is not modified.
 
-This adds a drive in snapshot mode, making it effectively
-read-only.
+=item C<format>
 
-Note that writes to the device are allowed, and will be seen for
-the duration of the guestfs handle, but they are written
-to a temporary file which is discarded as soon as the guestfs
-handle is closed.  We don't currently have any method to enable
-changes to be committed, although qemu can support this.
-
-This is equivalent to the qemu parameter
-C<-drive file=filename,snapshot=on,if=...>.
-
-C<if=...> is set at compile time by the configuration option
-C<./configure --with-drive-if=...>.  In the rare case where you
-might need to change this at run time, use C<$h-E<gt>add_drive_with_if>
-or C<$h-E<gt>add_drive_ro_with_if>.
+This forces the image format.  If you omit this (or use C<$h-E<gt>add_drive>
+or C<$h-E<gt>add_drive_ro>) then the format is automatically detected.
+Possible formats include C<raw> and C<qcow2>.
 
-Note that this call checks for the existence of C<filename>.  This
-stops you from specifying other types of drive which are supported
-by qemu such as C<nbd:> and C<http:> URLs.  To specify those, use
-the general C<$h-E<gt>config> call instead.
+Automatic detection of the format opens you up to a potential
+security hole when dealing with untrusted raw-format images.
+See CVE-2010-3851 and RHBZ#642934.  Specifying the format closes
+this security hole.
+
+=item C<iface>
+
+This rarely-used option lets you emulate the behaviour of the
+deprecated C<$h-E<gt>add_drive_with_if> call (q.v.)
+
+=back
+
+=item $h->add_drive_ro ($filename);
+
+This function is the equivalent of calling C<$h-E<gt>add_drive_opts>
+with the optional parameter C<GUESTFS_ADD_DRIVE_OPTS_READONLY> set to 1,
+so the disk is added read-only, with the format being detected
+automatically.
 
 =item $h->add_drive_ro_with_if ($filename, $iface);
 
 This is the same as C<$h-E<gt>add_drive_ro> but it allows you
 to specify the QEMU interface emulation to use at run time.
 
+This function is deprecated.
+In new code, use the C<add_drive_opts> call instead.
+
+Deprecated functions will not be removed from the API, but the
+fact that they are deprecated indicates that there are problems
+with correct use of these functions.
+
 =item $h->add_drive_with_if ($filename, $iface);
 
 This is the same as C<$h-E<gt>add_drive> but it allows you
 to specify the QEMU interface emulation to use at run time.
 
+This function is deprecated.
+In new code, use the C<add_drive_opts> call instead.
+
+Deprecated functions will not be removed from the API, but the
+fact that they are deprecated indicates that there are problems
+with correct use of these functions.
+
 =item $h->aug_clear ($augpath);
 
 Set the value associated with C<path> to C<NULL>.  This
diff -ur v1/php/extension/guestfs_php.c v2/php/extension/guestfs_php.c
--- v1/php/extension/guestfs_php.c	2010-10-22 16:40:46.746029347 +0100
+++ v2/php/extension/guestfs_php.c	2010-10-21 18:59:01.045680187 +0100
@@ -63,6 +63,7 @@
   PHP_FE (guestfs_last_error, NULL)
   PHP_FE (guestfs_add_cdrom, NULL)
   PHP_FE (guestfs_add_drive, NULL)
+  PHP_FE (guestfs_add_drive_opts, NULL)
   PHP_FE (guestfs_add_drive_ro, NULL)
   PHP_FE (guestfs_add_drive_ro_with_if, NULL)
   PHP_FE (guestfs_add_drive_with_if, NULL)
@@ -533,6 +534,59 @@
   RETURN_TRUE;
 }
 
+PHP_FUNCTION (guestfs_add_drive_opts)
+{
+  zval *z_g;
+  guestfs_h *g;
+  char *filename;
+  int filename_size;
+  struct guestfs_add_drive_opts_argv optargs_s = { .bitmask = 0 };
+  struct guestfs_add_drive_opts_argv *optargs = &optargs_s;
+  zend_bool optargs_t_readonly = -1;
+  char *optargs_t_format = NULL;
+  int optargs_t_format_size = -1;
+  char *optargs_t_iface = NULL;
+  int optargs_t_iface_size = -1;
+
+  if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "rs|bss",
+        &z_g, &filename, &filename_size, &optargs_t_readonly, &optargs_t_format, &optargs_t_format_size, &optargs_t_iface, &optargs_t_iface_size) == FAILURE) {
+    RETURN_FALSE;
+  }
+
+  ZEND_FETCH_RESOURCE (g, guestfs_h *, &z_g, -1, PHP_GUESTFS_HANDLE_RES_NAME,
+                       res_guestfs_h);
+  if (g == NULL) {
+    RETURN_FALSE;
+  }
+
+  if (strlen (filename) != filename_size) {
+    fprintf (stderr, "libguestfs: add_drive_opts: parameter 'filename' contains embedded ASCII NUL.\n");
+    RETURN_FALSE;
+  }
+
+  if (optargs_t_readonly != ((zend_bool)-1)) {
+    optargs_s.readonly = optargs_t_readonly;
+    optargs_s.bitmask |= GUESTFS_ADD_DRIVE_OPTS_READONLY_BITMASK;
+  }
+  if (optargs_t_format != NULL) {
+    optargs_s.format = optargs_t_format;
+    optargs_s.bitmask |= GUESTFS_ADD_DRIVE_OPTS_FORMAT_BITMASK;
+  }
+  if (optargs_t_iface != NULL) {
+    optargs_s.iface = optargs_t_iface;
+    optargs_s.bitmask |= GUESTFS_ADD_DRIVE_OPTS_IFACE_BITMASK;
+  }
+
+  int r;
+  r = guestfs_add_drive_opts_argv (g, filename, optargs);
+
+  if (r == -1) {
+    RETURN_FALSE;
+  }
+
+  RETURN_TRUE;
+}
+
 PHP_FUNCTION (guestfs_add_drive_ro)
 {
   zval *z_g;
diff -ur v1/php/extension/php_guestfs_php.h v2/php/extension/php_guestfs_php.h
--- v1/php/extension/php_guestfs_php.h	2010-10-22 16:40:46.658024412 +0100
+++ v2/php/extension/php_guestfs_php.h	2010-10-21 18:11:25.347503018 +0100
@@ -38,6 +38,7 @@
 PHP_FUNCTION (guestfs_last_error);
 PHP_FUNCTION (guestfs_add_cdrom);
 PHP_FUNCTION (guestfs_add_drive);
+PHP_FUNCTION (guestfs_add_drive_opts);
 PHP_FUNCTION (guestfs_add_drive_ro);
 PHP_FUNCTION (guestfs_add_drive_ro_with_if);
 PHP_FUNCTION (guestfs_add_drive_with_if);
diff -ur v1/python/guestfs.py v2/python/guestfs.py
--- v1/python/guestfs.py	2010-10-22 16:40:46.131994913 +0100
+++ v2/python/guestfs.py	2010-10-21 22:05:49.882255334 +0100
@@ -23,7 +23,7 @@
 
 import guestfs
 g = guestfs.GuestFS ()
-g.add_drive ("guest.img")
+g.add_drive_opts ("guest.img", format="raw")
 g.launch ()
 parts = g.list_partitions ()
 
@@ -53,10 +53,10 @@
 To create a guestfs handle you usually have to perform the following
 sequence of calls:
 
-# Create the handle, call add_drive at least once, and possibly
+# Create the handle, call add_drive* at least once, and possibly
 # several times if the guest has multiple block devices:
 g = guestfs.GuestFS ()
-g.add_drive ("guest.img")
+g.add_drive_opts ("guest.img", format="raw")
 
 # Launch the qemu subprocess and wait for it to become ready:
 g.launch ()
@@ -171,34 +171,18 @@
         return libguestfsmod.kill_subprocess (self._o)
 
     def add_drive (self, filename):
-        u"""This function adds a virtual machine disk image
-        "filename" to the guest. The first time you call this
-        function, the disk appears as IDE disk 0 ("/dev/sda") in
-        the guest, the second time as "/dev/sdb", and so on.
-        
-        You don't necessarily need to be root when using
-        libguestfs. However you obviously do need sufficient
-        permissions to access the filename for whatever
-        operations you want to perform (ie. read access if you
-        just want to read the image or write access if you want
-        to modify the image).
-        
-        This is equivalent to the qemu parameter "-drive
-        file=filename,cache=off,if=...".
-        
-        "cache=off" is omitted in cases where it is not
-        supported by the underlying filesystem.
+        u"""This function is the equivalent of calling
+        "g.add_drive_opts" with no optional parameters, so the
+        disk is added writable, with the format being detected
+        automatically.
         
-        "if=..." is set at compile time by the configuration
-        option "./configure --with-drive-if=...". In the rare
-        case where you might need to change this at run time,
-        use "g.add_drive_with_if" or "g.add_drive_ro_with_if".
-        
-        Note that this call checks for the existence of
-        "filename". This stops you from specifying other types
-        of drive which are supported by qemu such as "nbd:" and
-        "http:" URLs. To specify those, use the general
-        "g.config" call instead.
+        Automatic detection of the format opens you up to a
+        potential security hole when dealing with untrusted
+        raw-format images. See CVE-2010-3851 and RHBZ#642934.
+        Specifying the format closes this security hole.
+        Therefore you should think about replacing calls to this
+        function with calls to "g.add_drive_opts", and
+        specifying the format.
         """
         return libguestfsmod.add_drive (self._o, filename)
 
@@ -221,33 +205,22 @@
         this as an efficient way to transfer large files
         into the guest), then you should probably use
         "g.add_drive_ro" instead.
+        
+        This function is deprecated. In new code, use the
+        "add_drive_opts" call instead.
+        
+        Deprecated functions will not be removed from the API,
+        but the fact that they are deprecated indicates that
+        there are problems with correct use of these functions.
         """
         return libguestfsmod.add_cdrom (self._o, filename)
 
     def add_drive_ro (self, filename):
-        u"""This adds a drive in snapshot mode, making it
-        effectively read-only.
-        
-        Note that writes to the device are allowed, and will be
-        seen for the duration of the guestfs handle, but they
-        are written to a temporary file which is discarded as
-        soon as the guestfs handle is closed. We don't currently
-        have any method to enable changes to be committed,
-        although qemu can support this.
-        
-        This is equivalent to the qemu parameter "-drive
-        file=filename,snapshot=on,if=...".
-        
-        "if=..." is set at compile time by the configuration
-        option "./configure --with-drive-if=...". In the rare
-        case where you might need to change this at run time,
-        use "g.add_drive_with_if" or "g.add_drive_ro_with_if".
-        
-        Note that this call checks for the existence of
-        "filename". This stops you from specifying other types
-        of drive which are supported by qemu such as "nbd:" and
-        "http:" URLs. To specify those, use the general
-        "g.config" call instead.
+        u"""This function is the equivalent of calling
+        "g.add_drive_opts" with the optional parameter
+        "GUESTFS_ADD_DRIVE_OPTS_READONLY" set to 1, so the disk
+        is added read-only, with the format being detected
+        automatically.
         """
         return libguestfsmod.add_drive_ro (self._o, filename)
 
@@ -572,6 +545,13 @@
     def add_drive_with_if (self, filename, iface):
         u"""This is the same as "g.add_drive" but it allows you to
         specify the QEMU interface emulation to use at run time.
+        
+        This function is deprecated. In new code, use the
+        "add_drive_opts" call instead.
+        
+        Deprecated functions will not be removed from the API,
+        but the fact that they are deprecated indicates that
+        there are problems with correct use of these functions.
         """
         return libguestfsmod.add_drive_with_if (self._o, filename, iface)
 
@@ -579,6 +559,13 @@
         u"""This is the same as "g.add_drive_ro" but it allows you
         to specify the QEMU interface emulation to use at run
         time.
+        
+        This function is deprecated. In new code, use the
+        "add_drive_opts" call instead.
+        
+        Deprecated functions will not be removed from the API,
+        but the fact that they are deprecated indicates that
+        there are problems with correct use of these functions.
         """
         return libguestfsmod.add_drive_ro_with_if (self._o, filename, iface)
 
@@ -917,6 +904,48 @@
         """
         return libguestfsmod.list_filesystems (self._o)
 
+    def add_drive_opts (self, filename, readonly=-1, format=None, iface=None):
+        u"""This function adds a virtual machine disk image
+        "filename" to libguestfs. The first time you call this
+        function, the disk appears as "/dev/sda", the second
+        time as "/dev/sdb", and so on.
+        
+        You don't necessarily need to be root when using
+        libguestfs. However you obviously do need sufficient
+        permissions to access the filename for whatever
+        operations you want to perform (ie. read access if you
+        just want to read the image or write access if you want
+        to modify the image).
+        
+        This call checks that "filename" exists.
+        
+        The optional arguments are:
+        
+        "readonly"
+        If true then the image is treated as read-only.
+        Writes are still allowed, but they are stored in a
+        temporary snapshot overlay which is discarded at the
+        end. The disk that you add is not modified.
+        
+        "format"
+        This forces the image format. If you omit this (or
+        use "g.add_drive" or "g.add_drive_ro") then the
+        format is automatically detected. Possible formats
+        include "raw" and "qcow2".
+        
+        Automatic detection of the format opens you up to a
+        potential security hole when dealing with untrusted
+        raw-format images. See CVE-2010-3851 and
+        RHBZ#642934. Specifying the format closes this
+        security hole.
+        
+        "iface"
+        This rarely-used option lets you emulate the
+        behaviour of the deprecated "g.add_drive_with_if"
+        call (q.v.)
+        """
+        return libguestfsmod.add_drive_opts (self._o, filename, readonly, format, iface)
+
     def mount (self, device, mountpoint):
         u"""Mount a guest disk at a position in the filesystem.
         Block devices are named "/dev/sda", "/dev/sdb" and so
diff -ur v1/python/guestfs-py.c v2/python/guestfs-py.c
--- v1/python/guestfs-py.c	2010-10-22 16:40:46.088992500 +0100
+++ v2/python/guestfs-py.c	2010-10-21 18:15:31.424219717 +0100
@@ -2288,6 +2288,51 @@
 }
 
 static PyObject *
+py_guestfs_add_drive_opts (PyObject *self, PyObject *args)
+{
+  PyObject *py_g;
+  guestfs_h *g;
+  PyObject *py_r;
+  struct guestfs_add_drive_opts_argv optargs_s;
+  struct guestfs_add_drive_opts_argv *optargs = &optargs_s;
+  int r;
+  const char *filename;
+  int optargs_t_readonly = -1;
+  const char *optargs_t_format = NULL;
+  const char *optargs_t_iface = NULL;
+
+  optargs_s.bitmask = 0;
+
+  if (!PyArg_ParseTuple (args, (char *) "Osizz:guestfs_add_drive_opts",
+                         &py_g, &filename, &optargs_t_readonly, &optargs_t_format, &optargs_t_iface))
+    return NULL;
+  g = get_handle (py_g);
+
+  if (optargs_t_readonly != -1) {
+    optargs_s.readonly = optargs_t_readonly;
+    optargs_s.bitmask |= GUESTFS_ADD_DRIVE_OPTS_READONLY_BITMASK;
+  }
+  if (optargs_t_format != NULL) {
+    optargs_s.format = optargs_t_format;
+    optargs_s.bitmask |= GUESTFS_ADD_DRIVE_OPTS_FORMAT_BITMASK;
+  }
+  if (optargs_t_iface != NULL) {
+    optargs_s.iface = optargs_t_iface;
+    optargs_s.bitmask |= GUESTFS_ADD_DRIVE_OPTS_IFACE_BITMASK;
+  }
+
+  r = guestfs_add_drive_opts_argv (g, filename, optargs);
+  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 PyObject *
 py_guestfs_mount (PyObject *self, PyObject *args)
 {
   PyObject *py_g;
@@ -9451,6 +9496,7 @@
   { (char *) "set_network", py_guestfs_set_network, METH_VARARGS, NULL },
   { (char *) "get_network", py_guestfs_get_network, METH_VARARGS, NULL },
   { (char *) "list_filesystems", py_guestfs_list_filesystems, METH_VARARGS, NULL },
+  { (char *) "add_drive_opts", py_guestfs_add_drive_opts, METH_VARARGS, NULL },
   { (char *) "mount", py_guestfs_mount, METH_VARARGS, NULL },
   { (char *) "sync", py_guestfs_sync, METH_VARARGS, NULL },
   { (char *) "touch", py_guestfs_touch, METH_VARARGS, NULL },
diff -ur v1/ruby/ext/guestfs/_guestfs.c v2/ruby/ext/guestfs/_guestfs.c
--- v1/ruby/ext/guestfs/_guestfs.c	2010-10-22 16:40:46.234000632 +0100
+++ v2/ruby/ext/guestfs/_guestfs.c	2010-10-21 16:12:15.007761790 +0100
@@ -1614,6 +1614,50 @@
   return rv;
 }
 
+static VALUE ruby_guestfs_add_drive_opts (VALUE gv, VALUE filenamev, VALUE optargsv)
+{
+  guestfs_h *g;
+  Data_Get_Struct (gv, guestfs_h, g);
+  if (!g)
+    rb_raise (rb_eArgError, "%s: used handle after closing it", "add_drive_opts");
+
+  Check_Type (filenamev, T_STRING);
+  const char *filename = StringValueCStr (filenamev);
+  if (!filename)
+    rb_raise (rb_eTypeError, "expected string for parameter %s of %s",
+              "filename", "add_drive_opts");
+
+  Check_Type (optargsv, T_HASH);
+  struct guestfs_add_drive_opts_argv optargs_s = { .bitmask = 0 };
+  struct guestfs_add_drive_opts_argv *optargs = &optargs_s;
+  VALUE v;
+  v = rb_hash_lookup (optargsv, ID2SYM (rb_intern ("readonly")));
+  if (v != Qnil) {
+    optargs_s.readonly = RTEST (v);
+    optargs_s.bitmask |= GUESTFS_ADD_DRIVE_OPTS_READONLY_BITMASK;
+  }
+  v = rb_hash_lookup (optargsv, ID2SYM (rb_intern ("format")));
+  if (v != Qnil) {
+    Check_Type (v, T_STRING);
+    optargs_s.format = StringValueCStr (v);
+    optargs_s.bitmask |= GUESTFS_ADD_DRIVE_OPTS_FORMAT_BITMASK;
+  }
+  v = rb_hash_lookup (optargsv, ID2SYM (rb_intern ("iface")));
+  if (v != Qnil) {
+    Check_Type (v, T_STRING);
+    optargs_s.iface = StringValueCStr (v);
+    optargs_s.bitmask |= GUESTFS_ADD_DRIVE_OPTS_IFACE_BITMASK;
+  }
+
+  int r;
+
+  r = guestfs_add_drive_opts_argv (g, filename, optargs);
+  if (r == -1)
+    rb_raise (e_Error, "%s", guestfs_last_error (g));
+
+  return Qnil;
+}
+
 static VALUE ruby_guestfs_mount (VALUE gv, VALUE devicev, VALUE mountpointv)
 {
   guestfs_h *g;
@@ -9004,6 +9048,8 @@
         ruby_guestfs_get_network, 0);
   rb_define_method (c_guestfs, "list_filesystems",
         ruby_guestfs_list_filesystems, 0);
+  rb_define_method (c_guestfs, "add_drive_opts",
+        ruby_guestfs_add_drive_opts, 2);
   rb_define_method (c_guestfs, "mount",
         ruby_guestfs_mount, 2);
   rb_define_method (c_guestfs, "sync",
diff -ur v1/src/actions.c v2/src/actions.c
--- v1/src/actions.c	2010-10-22 16:40:45.016932379 +0100
+++ v2/src/actions.c	2010-10-21 12:21:53.489339728 +0100
@@ -1075,6 +1075,49 @@
   return guestfs__list_filesystems (g);
 }
 
+int guestfs_add_drive_opts_argv (guestfs_h *g,
+		const char *filename,
+		const struct guestfs_add_drive_opts_argv *optargs)
+{
+  if (filename == NULL) {
+    error (g, "%s: %s: parameter cannot be NULL",
+           "add_drive_opts", "filename");
+    return -1;
+  }
+  if ((optargs->bitmask & GUESTFS_ADD_DRIVE_OPTS_FORMAT_BITMASK) &&
+      optargs->format == NULL) {
+    error (g, "%s: %s: optional parameter cannot be NULL",
+           "add_drive_opts", "format");
+    return -1;
+  }
+  if ((optargs->bitmask & GUESTFS_ADD_DRIVE_OPTS_IFACE_BITMASK) &&
+      optargs->iface == NULL) {
+    error (g, "%s: %s: optional parameter cannot be NULL",
+           "add_drive_opts", "iface");
+    return -1;
+  }
+
+  if (optargs->bitmask & 0xfffffffffffffff8ULL) {
+    error (g, "%s: unknown option in guestfs_%s_argv->bitmask (this can happen if a program is compiled against a newer version of libguestfs, then dynamically linked to an older version)",
+           "add_drive_opts", "add_drive_opts");
+    return -1;
+  }
+
+  if (guestfs__get_trace (g)) {
+    fprintf (stderr, "add_drive_opts");
+    fprintf (stderr, " \"%s\"", filename);
+    if (optargs->bitmask & GUESTFS_ADD_DRIVE_OPTS_READONLY_BITMASK)
+      fprintf (stderr, " \"%s:%s\"", "readonly", optargs->readonly ? "true" : "false");
+    if (optargs->bitmask & GUESTFS_ADD_DRIVE_OPTS_FORMAT_BITMASK)
+      fprintf (stderr, " \"%s:%s\"", "format", optargs->format);
+    if (optargs->bitmask & GUESTFS_ADD_DRIVE_OPTS_IFACE_BITMASK)
+      fprintf (stderr, " \"%s:%s\"", "iface", optargs->iface);
+    fputc ('\n', stderr);
+  }
+
+  return guestfs__add_drive_opts (g, filename, optargs);
+}
+
 int guestfs_mount (guestfs_h *g,
 		const char *device,
 		const char *mountpoint)
@@ -18759,3 +18802,55 @@
   free (x);
 }
 
+int guestfs_add_drive_opts (guestfs_h *g,
+		const char *filename,
+		...)
+{
+  va_list optargs;
+
+  va_start (optargs, filename);
+  int r = guestfs_add_drive_opts_va (g, filename, optargs);
+  va_end (optargs);
+
+  return r;
+}
+
+int guestfs_add_drive_opts_va (guestfs_h *g,
+		const char *filename,
+		va_list args)
+{
+  struct guestfs_add_drive_opts_argv optargs_s;
+  struct guestfs_add_drive_opts_argv *optargs = &optargs_s;
+  int i;
+
+  optargs_s.bitmask = 0;
+
+  while ((i = va_arg (args, int)) >= 0) {
+    switch (i) {
+    case GUESTFS_ADD_DRIVE_OPTS_READONLY:
+      optargs_s.readonly = va_arg (args, int);
+      break;
+    case GUESTFS_ADD_DRIVE_OPTS_FORMAT:
+      optargs_s.format = va_arg (args, const char *);
+      break;
+    case GUESTFS_ADD_DRIVE_OPTS_IFACE:
+      optargs_s.iface = va_arg (args, const char *);
+      break;
+    default:
+      error (g, "%s: unknown option %d (this can happen if a program is compiled against a newer version of libguestfs, then dynamically linked to an older version)",
+             "add_drive_opts", i);
+      return -1;
+    }
+
+    uint64_t i_mask = 1ULL << i;
+    if (optargs_s.bitmask & i_mask) {
+      error (g, "%s: same optional argument specified more than once",
+             "add_drive_opts");
+      return -1;
+    }
+    optargs_s.bitmask |= i_mask;
+  }
+
+  return guestfs_add_drive_opts_argv (g, filename, optargs);
+}
+
diff -ur v1/src/guestfs-actions.h v2/src/guestfs-actions.h
--- v1/src/guestfs-actions.h	2010-10-22 16:40:44.882924864 +0100
+++ v2/src/guestfs-actions.h	2010-10-21 12:21:53.353332157 +0100
@@ -20,15 +20,40 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define LIBGUESTFS_HAVE_ADD_CDROM 1
 extern int guestfs_add_cdrom (guestfs_h *g, const char *filename);
 #define LIBGUESTFS_HAVE_ADD_DRIVE 1
 extern int guestfs_add_drive (guestfs_h *g, const char *filename);
+#define LIBGUESTFS_HAVE_ADD_DRIVE_OPTS 1
+extern int guestfs_add_drive_opts (guestfs_h *g, const char *filename, ...);
+extern int guestfs_add_drive_opts_va (guestfs_h *g, const char *filename, va_list args);
+struct guestfs_add_drive_opts_argv {
+  uint64_t bitmask;
+#define GUESTFS_ADD_DRIVE_OPTS_READONLY 0
+#define GUESTFS_ADD_DRIVE_OPTS_READONLY_BITMASK (1ULL<<0)
+/* The field below is only valid in this struct if the
+ * GUESTFS_ADD_DRIVE_OPTS_READONLY_BITMASK bit is set
+ * in the bitmask above, otherwise the contents are ignored.
+ */
+  int readonly;
+#define GUESTFS_ADD_DRIVE_OPTS_FORMAT 1
+#define GUESTFS_ADD_DRIVE_OPTS_FORMAT_BITMASK (1ULL<<1)
+/* The field below is only valid in this struct if the
+ * GUESTFS_ADD_DRIVE_OPTS_FORMAT_BITMASK bit is set
+ * in the bitmask above, otherwise the contents are ignored.
+ */
+  const char *format;
+#define GUESTFS_ADD_DRIVE_OPTS_IFACE 2
+#define GUESTFS_ADD_DRIVE_OPTS_IFACE_BITMASK (1ULL<<2)
+/* The field below is only valid in this struct if the
+ * GUESTFS_ADD_DRIVE_OPTS_IFACE_BITMASK bit is set
+ * in the bitmask above, otherwise the contents are ignored.
+ */
+  const char *iface;
+};
+extern int guestfs_add_drive_opts_argv (guestfs_h *g, const char *filename, const struct guestfs_add_drive_opts_argv *optargs);
 #define LIBGUESTFS_HAVE_ADD_DRIVE_RO 1
 extern int guestfs_add_drive_ro (guestfs_h *g, const char *filename);
-#define LIBGUESTFS_HAVE_ADD_DRIVE_RO_WITH_IF 1
 extern int guestfs_add_drive_ro_with_if (guestfs_h *g, const char *filename, const char *iface);
-#define LIBGUESTFS_HAVE_ADD_DRIVE_WITH_IF 1
 extern int guestfs_add_drive_with_if (guestfs_h *g, const char *filename, const char *iface);
 #define LIBGUESTFS_HAVE_AUG_CLEAR 1
 extern int guestfs_aug_clear (guestfs_h *g, const char *augpath);
diff -ur v1/src/guestfs-actions.pod v2/src/guestfs-actions.pod
--- v1/src/guestfs-actions.pod	2010-10-22 16:40:45.083936137 +0100
+++ v2/src/guestfs-actions.pod	2010-10-21 12:20:01.212087941 +0100
@@ -28,14 +28,49 @@
 
 This function returns 0 on success or -1 on error.
 
+This function is deprecated.
+In new code, use the C<add_drive_opts> call instead.
+
+Deprecated functions will not be removed from the API, but the
+fact that they are deprecated indicates that there are problems
+with correct use of these functions.
+
 =head2 guestfs_add_drive
 
  int guestfs_add_drive (guestfs_h *g,
 		const char *filename);
 
-This function adds a virtual machine disk image C<filename> to the
-guest.  The first time you call this function, the disk appears as IDE
-disk 0 (C</dev/sda>) in the guest, the second time as C</dev/sdb>, and
+This function is the equivalent of calling C<guestfs_add_drive_opts>
+with no optional parameters, so the disk is added writable, with
+the format being detected automatically.
+
+Automatic detection of the format opens you up to a potential
+security hole when dealing with untrusted raw-format images.
+See CVE-2010-3851 and RHBZ#642934.  Specifying the format closes
+this security hole.  Therefore you should think about replacing
+calls to this function with calls to C<guestfs_add_drive_opts>,
+and specifying the format.
+
+This function returns 0 on success or -1 on error.
+
+=head2 guestfs_add_drive_opts
+
+ int guestfs_add_drive_opts (guestfs_h *g,
+		const char *filename,
+		...);
+
+You may supply a list of optional arguments to this call.
+Use zero or more of the following pairs of parameters,
+and terminate the list with C<-1> on its own.
+See L</CALLS WITH OPTIONAL ARGUMENTS>.
+
+ GUESTFS_ADD_DRIVE_OPTS_READONLY, int readonly,
+ GUESTFS_ADD_DRIVE_OPTS_FORMAT, const char *format,
+ GUESTFS_ADD_DRIVE_OPTS_IFACE, const char *iface,
+
+This function adds a virtual machine disk image C<filename> to
+libguestfs.  The first time you call this function, the disk
+appears as C</dev/sda>, the second time as C</dev/sdb>, and
 so on.
 
 You don't necessarily need to be root when using libguestfs.  However
@@ -44,50 +79,67 @@
 just want to read the image or write access if you want to modify the
 image).
 
-This is equivalent to the qemu parameter
-C<-drive file=filename,cache=off,if=...>.
+This call checks that C<filename> exists.
+
+The optional arguments are:
+
+=over 4
+
+=item C<readonly>
+
+If true then the image is treated as read-only.  Writes are still
+allowed, but they are stored in a temporary snapshot overlay which
+is discarded at the end.  The disk that you add is not modified.
 
-C<cache=off> is omitted in cases where it is not supported by
-the underlying filesystem.
+=item C<format>
 
-C<if=...> is set at compile time by the configuration option
-C<./configure --with-drive-if=...>.  In the rare case where you
-might need to change this at run time, use C<guestfs_add_drive_with_if>
-or C<guestfs_add_drive_ro_with_if>.
-
-Note that this call checks for the existence of C<filename>.  This
-stops you from specifying other types of drive which are supported
-by qemu such as C<nbd:> and C<http:> URLs.  To specify those, use
-the general C<guestfs_config> call instead.
+This forces the image format.  If you omit this (or use C<guestfs_add_drive>
+or C<guestfs_add_drive_ro>) then the format is automatically detected.
+Possible formats include C<raw> and C<qcow2>.
+
+Automatic detection of the format opens you up to a potential
+security hole when dealing with untrusted raw-format images.
+See CVE-2010-3851 and RHBZ#642934.  Specifying the format closes
+this security hole.
+
+=item C<iface>
+
+This rarely-used option lets you emulate the behaviour of the
+deprecated C<guestfs_add_drive_with_if> call (q.v.)
+
+=back
 
 This function returns 0 on success or -1 on error.
 
+=head2 guestfs_add_drive_opts_va
+
+ int guestfs_add_drive_opts_va (guestfs_h *g,
+		const char *filename,
+		va_list args);
+
+This is the "va_list variant" of L</guestfs_add_drive_opts>.
+
+See L</CALLS WITH OPTIONAL ARGUMENTS>.
+
+=head2 guestfs_add_drive_opts_argv
+
+ int guestfs_add_drive_opts_argv (guestfs_h *g,
+		const char *filename,
+		const struct guestfs_add_drive_opts_argv *optargs);
+
+This is the "argv variant" of L</guestfs_add_drive_opts>.
+
+See L</CALLS WITH OPTIONAL ARGUMENTS>.
+
 =head2 guestfs_add_drive_ro
 
  int guestfs_add_drive_ro (guestfs_h *g,
 		const char *filename);
 
-This adds a drive in snapshot mode, making it effectively
-read-only.
-
-Note that writes to the device are allowed, and will be seen for
-the duration of the guestfs handle, but they are written
-to a temporary file which is discarded as soon as the guestfs
-handle is closed.  We don't currently have any method to enable
-changes to be committed, although qemu can support this.
-
-This is equivalent to the qemu parameter
-C<-drive file=filename,snapshot=on,if=...>.
-
-C<if=...> is set at compile time by the configuration option
-C<./configure --with-drive-if=...>.  In the rare case where you
-might need to change this at run time, use C<guestfs_add_drive_with_if>
-or C<guestfs_add_drive_ro_with_if>.
-
-Note that this call checks for the existence of C<filename>.  This
-stops you from specifying other types of drive which are supported
-by qemu such as C<nbd:> and C<http:> URLs.  To specify those, use
-the general C<guestfs_config> call instead.
+This function is the equivalent of calling C<guestfs_add_drive_opts>
+with the optional parameter C<GUESTFS_ADD_DRIVE_OPTS_READONLY> set to 1,
+so the disk is added read-only, with the format being detected
+automatically.
 
 This function returns 0 on success or -1 on error.
 
@@ -102,6 +154,13 @@
 
 This function returns 0 on success or -1 on error.
 
+This function is deprecated.
+In new code, use the C<add_drive_opts> call instead.
+
+Deprecated functions will not be removed from the API, but the
+fact that they are deprecated indicates that there are problems
+with correct use of these functions.
+
 =head2 guestfs_add_drive_with_if
 
  int guestfs_add_drive_with_if (guestfs_h *g,
@@ -113,6 +172,13 @@
 
 This function returns 0 on success or -1 on error.
 
+This function is deprecated.
+In new code, use the C<add_drive_opts> call instead.
+
+Deprecated functions will not be removed from the API, but the
+fact that they are deprecated indicates that there are problems
+with correct use of these functions.
+
 =head2 guestfs_aug_clear
 
  int guestfs_aug_clear (guestfs_h *g,
diff -ur v1/src/guestfs-internal-actions.h v2/src/guestfs-internal-actions.h
--- v1/src/guestfs-internal-actions.h	2010-10-22 16:40:44.886925088 +0100
+++ v2/src/guestfs-internal-actions.h	2010-10-20 17:56:03.257272592 +0100
@@ -90,3 +90,4 @@
 extern int guestfs__set_network (guestfs_h *g, int network);
 extern int guestfs__get_network (guestfs_h *g);
 extern char **guestfs__list_filesystems (guestfs_h *g);
+extern int guestfs__add_drive_opts (guestfs_h *g, const char *filename, const struct guestfs_add_drive_opts_argv *optargs);
diff -ur v1/src/libguestfs.syms v2/src/libguestfs.syms
--- v1/src/libguestfs.syms	2010-10-22 16:40:45.103937259 +0100
+++ v2/src/libguestfs.syms	2010-10-20 17:30:41.553486233 +0100
@@ -23,6 +23,9 @@
     global:
         guestfs_add_cdrom;
         guestfs_add_drive;
+        guestfs_add_drive_opts;
+        guestfs_add_drive_opts_argv;
+        guestfs_add_drive_opts_va;
         guestfs_add_drive_ro;
         guestfs_add_drive_ro_with_if;
         guestfs_add_drive_with_if;


More information about the Libguestfs mailing list