From d1a1ab972bb22f4c38a21fcc73f81650aaa03b4e Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Tue, 2 Jun 2009 14:25:25 +0100 Subject: [PATCH] Generated code for 'add_drive_ro' call. --- capitests/tests.c | 6 ++-- fish/cmds.c | 25 ++++++++++++++-- fish/completion.c | 2 ++ guestfish-actions.pod | 31 ++++++++++++++++++++ guestfs-actions.pod | 34 ++++++++++++++++++++++ haskell/Guestfs.hs | 13 +++++++++ java/com/redhat/et/libguestfs/GuestFS.java | 46 ++++++++++++++++++++++++++++++ java/com_redhat_et_libguestfs_GuestFS.c | 17 +++++++++++ ocaml/guestfs.ml | 1 + ocaml/guestfs.mli | 3 ++ ocaml/guestfs_c_actions.c | 23 +++++++++++++++ perl/Guestfs.xs | 11 +++++++ perl/lib/Sys/Guestfs.pm | 29 +++++++++++++++++++ python/guestfs-py.c | 26 +++++++++++++++++ python/guestfs.py | 34 ++++++++++++++++++++++ ruby/ext/guestfs/_guestfs.c | 23 +++++++++++++++ src/guestfs-actions.h | 1 + 17 files changed, 320 insertions(+), 5 deletions(-) diff --git a/capitests/tests.c b/capitests/tests.c index 5b6356f..1b751e8 100644 --- a/capitests/tests.c +++ b/capitests/tests.c @@ -94,6 +94,7 @@ static void no_test_warnings (void) fprintf (stderr, "warning: \"guestfs_kill_subprocess\" has no tests\n"); fprintf (stderr, "warning: \"guestfs_add_drive\" has no tests\n"); fprintf (stderr, "warning: \"guestfs_add_cdrom\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_add_drive_ro\" has no tests\n"); fprintf (stderr, "warning: \"guestfs_config\" has no tests\n"); fprintf (stderr, "warning: \"guestfs_set_qemu\" has no tests\n"); fprintf (stderr, "warning: \"guestfs_get_qemu\" has no tests\n"); @@ -16020,7 +16021,6 @@ int main (int argc, char *argv[]) { char c = 0; int failed = 0; - const char *srcdir; const char *filename; int fd, i; int nr_tests, test_num = 0; @@ -16122,8 +16122,8 @@ int main (int argc, char *argv[]) exit (1); } - if (guestfs_add_drive (g, "../images/test.sqsh") == -1) { - printf ("guestfs_add_drive %s FAILED\n", filename); + if (guestfs_add_drive_ro (g, "../images/test.sqsh") == -1) { + printf ("guestfs_add_drive_ro ../images/test.sqsh FAILED\n"); exit (1); } diff --git a/fish/cmds.c b/fish/cmds.c index d200acf..bb982d4 100644 --- a/fish/cmds.c +++ b/fish/cmds.c @@ -33,6 +33,7 @@ void list_commands (void) 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-ro", "add a drive in snapshot mode (read-only)"); printf ("%-20s %s\n", "aug-close", "close the current Augeas handle"); printf ("%-20s %s\n", "aug-defnode", "define an Augeas node"); printf ("%-20s %s\n", "aug-defvar", "define an Augeas variable"); @@ -171,10 +172,13 @@ void display_command (const char *cmd) pod2text ("kill-subprocess - kill the qemu subprocess", " kill-subprocess\n\nThis kills the qemu subprocess. You should never need to call this."); else if (strcasecmp (cmd, "add_drive") == 0 || strcasecmp (cmd, "add-drive") == 0 || strcasecmp (cmd, "add") == 0) - pod2text ("add-drive - add an image to examine or modify", " add-drive \n\nThis function adds a virtual machine disk image C to the\nguest. The first time you call this function, the disk appears as IDE\ndisk 0 (C) in the guest, the second time as C, 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 C<-drive file=filename>.\n\nYou can use 'add' as an alias for this command."); + pod2text ("add-drive - add an image to examine or modify", " add-drive \n\nThis function adds a virtual machine disk image C to the\nguest. The first time you call this function, the disk appears as IDE\ndisk 0 (C) in the guest, the second time as C, 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 C<-drive file=filename>.\n\nNote that this call checks for the existence of C. This\nstops you from specifying other types of drive which are supported\nby qemu such as C and C URLs. To specify those, use\nthe general C call instead.\n\nYou can use 'add' as an alias for this command."); else if (strcasecmp (cmd, "add_cdrom") == 0 || strcasecmp (cmd, "add-cdrom") == 0 || strcasecmp (cmd, "cdrom") == 0) - pod2text ("add-cdrom - add a CD-ROM disk image to examine", " add-cdrom \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\nYou can use 'cdrom' as an alias for this command."); + pod2text ("add-cdrom - add a CD-ROM disk image to examine", " add-cdrom \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\nNote that this call checks for the existence of C. This\nstops you from specifying other types of drive which are supported\nby qemu such as C and C URLs. To specify those, use\nthe general C call instead.\n\nYou can use 'cdrom' as an alias for this command."); + else + if (strcasecmp (cmd, "add_drive_ro") == 0 || strcasecmp (cmd, "add-drive-ro") == 0 || strcasecmp (cmd, "add-ro") == 0) + pod2text ("add-drive-ro - add a drive in snapshot mode (read-only)", " add-drive-ro \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>.\n\nNote that this call checks for the existence of C. This\nstops you from specifying other types of drive which are supported\nby qemu such as C and C URLs. To specify those, use\nthe general C call instead.\n\nYou can use 'add-ro' as an alias for this command."); else if (strcasecmp (cmd, "config") == 0) pod2text ("config - add qemu parameters", " config \n\nThis can be used to add arbitrary qemu command line parameters\nof the form C<-param value>. Actually it's not quite arbitrary - we\nprevent you from setting some parameters which would interfere with\nparameters that we use.\n\nThe first character of C string must be a C<-> (dash).\n\nC can be NULL."); @@ -737,6 +741,20 @@ static int run_add_cdrom (const char *cmd, int argc, char *argv[]) return r; } +static int run_add_drive_ro (const char *cmd, int argc, char *argv[]) +{ + int r; + const char *filename; + if (argc != 1) { + fprintf (stderr, "%s should have 1 parameter(s)\n", cmd); + fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd); + return -1; + } + filename = argv[0]; + r = guestfs_add_drive_ro (g, filename); + return r; +} + static int run_config (const char *cmd, int argc, char *argv[]) { int r; @@ -2694,6 +2712,9 @@ int run_action (const char *cmd, int argc, char *argv[]) if (strcasecmp (cmd, "add_cdrom") == 0 || strcasecmp (cmd, "add-cdrom") == 0 || strcasecmp (cmd, "cdrom") == 0) return run_add_cdrom (cmd, argc, argv); else + if (strcasecmp (cmd, "add_drive_ro") == 0 || strcasecmp (cmd, "add-drive-ro") == 0 || strcasecmp (cmd, "add-ro") == 0) + return run_add_drive_ro (cmd, argc, argv); + else if (strcasecmp (cmd, "config") == 0) return run_config (cmd, argc, argv); else diff --git a/fish/completion.c b/fish/completion.c index 305e810..287c5aa 100644 --- a/fish/completion.c +++ b/fish/completion.c @@ -42,6 +42,8 @@ static const char *const commands[] = { "add", "add-cdrom", "cdrom", + "add-drive-ro", + "add-ro", "config", "set-qemu", "qemu", diff --git a/guestfish-actions.pod b/guestfish-actions.pod index fa82ef1..9b07c40 100644 --- a/guestfish-actions.pod +++ b/guestfish-actions.pod @@ -6,6 +6,11 @@ This function adds a virtual CD-ROM disk image to the guest. This is equivalent to the qemu parameter C<-cdrom filename>. +Note that this call checks for the existence of C. This +stops you from specifying other types of drive which are supported +by qemu such as C and C URLs. To specify those, use +the general C call instead. + =head2 add-drive | add add-drive filename @@ -23,6 +28,32 @@ image). This is equivalent to the qemu parameter C<-drive file=filename>. +Note that this call checks for the existence of C. This +stops you from specifying other types of drive which are supported +by qemu such as C and C URLs. To specify those, use +the general C call instead. + +=head2 add-drive-ro | add-ro + + 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>. + +Note that this call checks for the existence of C. This +stops you from specifying other types of drive which are supported +by qemu such as C and C URLs. To specify those, use +the general C call instead. + =head2 aug-close aug-close diff --git a/guestfs-actions.pod b/guestfs-actions.pod index 0b06470..2705c3b 100644 --- a/guestfs-actions.pod +++ b/guestfs-actions.pod @@ -7,6 +7,11 @@ This function adds a virtual CD-ROM disk image to the guest. This is equivalent to the qemu parameter C<-cdrom filename>. +Note that this call checks for the existence of C. This +stops you from specifying other types of drive which are supported +by qemu such as C and C URLs. To specify those, use +the general C call instead. + This function returns 0 on success or -1 on error. =head2 guestfs_add_drive @@ -27,6 +32,35 @@ image). This is equivalent to the qemu parameter C<-drive file=filename>. +Note that this call checks for the existence of C. This +stops you from specifying other types of drive which are supported +by qemu such as C and C URLs. To specify those, use +the general C call instead. + +This function returns 0 on success or -1 on error. + +=head2 guestfs_add_drive_ro + + int guestfs_add_drive_ro (guestfs_h *handle, + 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>. + +Note that this call checks for the existence of C. This +stops you from specifying other types of drive which are supported +by qemu such as C and C URLs. To specify those, use +the general C call instead. + This function returns 0 on success or -1 on error. =head2 guestfs_aug_close diff --git a/haskell/Guestfs.hs b/haskell/Guestfs.hs index ee7dabd..210274e 100644 --- a/haskell/Guestfs.hs +++ b/haskell/Guestfs.hs @@ -29,6 +29,7 @@ module Guestfs ( kill_subprocess, add_drive, add_cdrom, + add_drive_ro, config, set_qemu, set_path, @@ -192,6 +193,18 @@ add_cdrom h filename = do fail err else return () +foreign import ccall unsafe "guestfs_add_drive_ro" c_add_drive_ro + :: GuestfsP -> CString -> IO (CInt) + +add_drive_ro :: GuestfsH -> String -> IO () +add_drive_ro h filename = do + r <- withCString filename $ \filename -> withForeignPtr h (\p -> c_add_drive_ro p filename) + if (r == -1) + then do + err <- last_error h + fail err + else return () + foreign import ccall unsafe "guestfs_config" c_config :: GuestfsP -> CString -> CString -> IO (CInt) diff --git a/java/com/redhat/et/libguestfs/GuestFS.java b/java/com/redhat/et/libguestfs/GuestFS.java index d340b8c..1d00547 100644 --- a/java/com/redhat/et/libguestfs/GuestFS.java +++ b/java/com/redhat/et/libguestfs/GuestFS.java @@ -429,6 +429,12 @@ public HashMap test0rhashtableerr () * This is equivalent to the qemu parameter "-drive * file=filename". *

+ * 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. + *

* @throws LibGuestFSException */ public void add_drive (String filename) @@ -450,6 +456,12 @@ public HashMap test0rhashtableerr () * This is equivalent to the qemu parameter "-cdrom * filename". *

+ * 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. + *

* @throws LibGuestFSException */ public void add_cdrom (String filename) @@ -463,6 +475,40 @@ public HashMap test0rhashtableerr () throws LibGuestFSException; /** + * add a drive in snapshot mode (read-only) + *

+ * 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". + *

+ * 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. + *

+ * @throws LibGuestFSException + */ + public void add_drive_ro (String filename) + throws LibGuestFSException + { + if (g == 0) + throw new LibGuestFSException ("add_drive_ro: handle is closed"); + _add_drive_ro (g, filename); + } + private native void _add_drive_ro (long g, String filename) + throws LibGuestFSException; + + /** * add qemu parameters *

* This can be used to add arbitrary qemu command line diff --git a/java/com_redhat_et_libguestfs_GuestFS.c b/java/com_redhat_et_libguestfs_GuestFS.c index c5971c5..fc858f6 100644 --- a/java/com_redhat_et_libguestfs_GuestFS.c +++ b/java/com_redhat_et_libguestfs_GuestFS.c @@ -1089,6 +1089,23 @@ Java_com_redhat_et_libguestfs_GuestFS__1add_1cdrom } JNIEXPORT void JNICALL +Java_com_redhat_et_libguestfs_GuestFS__1add_1drive_1ro + (JNIEnv *env, jobject obj, jlong jg, jstring jfilename) +{ + guestfs_h *g = (guestfs_h *) (long) jg; + int r; + const char *filename; + + filename = (*env)->GetStringUTFChars (env, jfilename, NULL); + r = guestfs_add_drive_ro (g, filename); + (*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__1config (JNIEnv *env, jobject obj, jlong jg, jstring jqemuparam, jstring jqemuvalue) { diff --git a/ocaml/guestfs.ml b/ocaml/guestfs.ml index d218b3e..cf75d7b 100644 --- a/ocaml/guestfs.ml +++ b/ocaml/guestfs.ml @@ -147,6 +147,7 @@ external wait_ready : t -> unit = "ocaml_guestfs_wait_ready" external kill_subprocess : t -> unit = "ocaml_guestfs_kill_subprocess" external add_drive : t -> string -> unit = "ocaml_guestfs_add_drive" external add_cdrom : t -> string -> unit = "ocaml_guestfs_add_cdrom" +external add_drive_ro : t -> string -> unit = "ocaml_guestfs_add_drive_ro" external config : t -> string -> string option -> unit = "ocaml_guestfs_config" external set_qemu : t -> string -> unit = "ocaml_guestfs_set_qemu" external get_qemu : t -> string = "ocaml_guestfs_get_qemu" diff --git a/ocaml/guestfs.mli b/ocaml/guestfs.mli index 564f163..686bc60 100644 --- a/ocaml/guestfs.mli +++ b/ocaml/guestfs.mli @@ -220,6 +220,9 @@ val add_drive : t -> string -> unit val add_cdrom : t -> string -> unit (** add a CD-ROM disk image to examine *) +val add_drive_ro : t -> string -> unit +(** add a drive in snapshot mode (read-only) *) + val config : t -> string -> string option -> unit (** add qemu parameters *) diff --git a/ocaml/guestfs_c_actions.c b/ocaml/guestfs_c_actions.c index 74c25d9..73dfdd9 100644 --- a/ocaml/guestfs_c_actions.c +++ b/ocaml/guestfs_c_actions.c @@ -1094,6 +1094,29 @@ ocaml_guestfs_add_cdrom (value gv, value filenamev) } CAMLprim value +ocaml_guestfs_add_drive_ro (value gv, value filenamev) +{ + CAMLparam2 (gv, filenamev); + CAMLlocal1 (rv); + + guestfs_h *g = Guestfs_val (gv); + if (g == NULL) + caml_failwith ("add_drive_ro: used handle after closing it"); + + const char *filename = String_val (filenamev); + int r; + + caml_enter_blocking_section (); + r = guestfs_add_drive_ro (g, filename); + caml_leave_blocking_section (); + if (r == -1) + ocaml_guestfs_raise_error (g, "add_drive_ro"); + + rv = Val_unit; + CAMLreturn (rv); +} + +CAMLprim value ocaml_guestfs_config (value gv, value qemuparamv, value qemuvaluev) { CAMLparam3 (gv, qemuparamv, qemuvaluev); diff --git a/perl/Guestfs.xs b/perl/Guestfs.xs index 0f90aff..08b55b8 100644 --- a/perl/Guestfs.xs +++ b/perl/Guestfs.xs @@ -724,6 +724,17 @@ PREINIT: croak ("add_cdrom: %s", guestfs_last_error (g)); void +add_drive_ro (g, filename) + guestfs_h *g; + char *filename; +PREINIT: + int r; + PPCODE: + r = guestfs_add_drive_ro (g, filename); + if (r == -1) + croak ("add_drive_ro: %s", guestfs_last_error (g)); + +void config (g, qemuparam, qemuvalue) guestfs_h *g; char *qemuparam; diff --git a/perl/lib/Sys/Guestfs.pm b/perl/lib/Sys/Guestfs.pm index cba0032..f8e6b77 100644 --- a/perl/lib/Sys/Guestfs.pm +++ b/perl/lib/Sys/Guestfs.pm @@ -97,6 +97,11 @@ This function adds a virtual CD-ROM disk image to the guest. This is equivalent to the qemu parameter C<-cdrom filename>. +Note that this call checks for the existence of C. This +stops you from specifying other types of drive which are supported +by qemu such as C and C URLs. To specify those, use +the general C<$h-Econfig> call instead. + =item $h->add_drive ($filename); This function adds a virtual machine disk image C to the @@ -112,6 +117,30 @@ image). This is equivalent to the qemu parameter C<-drive file=filename>. +Note that this call checks for the existence of C. This +stops you from specifying other types of drive which are supported +by qemu such as C and C URLs. To specify those, use +the general C<$h-Econfig> call instead. + +=item $h->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>. + +Note that this call checks for the existence of C. This +stops you from specifying other types of drive which are supported +by qemu such as C and C URLs. To specify those, use +the general C<$h-Econfig> call instead. + =item $h->aug_close (); Close the current Augeas handle and free up any resources diff --git a/python/guestfs-py.c b/python/guestfs-py.c index 6ac3bd9..71ef85e 100644 --- a/python/guestfs-py.c +++ b/python/guestfs-py.c @@ -1179,6 +1179,31 @@ py_guestfs_add_cdrom (PyObject *self, PyObject *args) } static PyObject * +py_guestfs_add_drive_ro (PyObject *self, PyObject *args) +{ + PyObject *py_g; + guestfs_h *g; + PyObject *py_r; + int r; + const char *filename; + + if (!PyArg_ParseTuple (args, (char *) "Os:guestfs_add_drive_ro", + &py_g, &filename)) + return NULL; + g = get_handle (py_g); + + r = guestfs_add_drive_ro (g, filename); + 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_config (PyObject *self, PyObject *args) { PyObject *py_g; @@ -4416,6 +4441,7 @@ static PyMethodDef methods[] = { { (char *) "kill_subprocess", py_guestfs_kill_subprocess, METH_VARARGS, NULL }, { (char *) "add_drive", py_guestfs_add_drive, METH_VARARGS, NULL }, { (char *) "add_cdrom", py_guestfs_add_cdrom, METH_VARARGS, NULL }, + { (char *) "add_drive_ro", py_guestfs_add_drive_ro, METH_VARARGS, NULL }, { (char *) "config", py_guestfs_config, METH_VARARGS, NULL }, { (char *) "set_qemu", py_guestfs_set_qemu, METH_VARARGS, NULL }, { (char *) "get_qemu", py_guestfs_get_qemu, METH_VARARGS, NULL }, diff --git a/python/guestfs.py b/python/guestfs.py index 4f32ae7..a75148e 100644 --- a/python/guestfs.py +++ b/python/guestfs.py @@ -198,6 +198,12 @@ class GuestFS: This is equivalent to the qemu parameter "-drive file=filename". + + 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. """ return libguestfsmod.add_drive (self._o, filename) @@ -207,9 +213,37 @@ class GuestFS: This is equivalent to the qemu parameter "-cdrom filename". + + 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. """ 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". + + 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. + """ + return libguestfsmod.add_drive_ro (self._o, filename) + def config (self, qemuparam, qemuvalue): u"""This can be used to add arbitrary qemu command line parameters of the form "-param value". Actually it's not diff --git a/ruby/ext/guestfs/_guestfs.c b/ruby/ext/guestfs/_guestfs.c index 6fb2608..4983932 100644 --- a/ruby/ext/guestfs/_guestfs.c +++ b/ruby/ext/guestfs/_guestfs.c @@ -941,6 +941,27 @@ static VALUE ruby_guestfs_add_cdrom (VALUE gv, VALUE filenamev) return Qnil; } +static VALUE ruby_guestfs_add_drive_ro (VALUE gv, VALUE filenamev) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "add_drive_ro"); + + const char *filename = StringValueCStr (filenamev); + if (!filename) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "filename", "add_drive_ro"); + + int r; + + r = guestfs_add_drive_ro (g, filename); + if (r == -1) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + return Qnil; +} + static VALUE ruby_guestfs_config (VALUE gv, VALUE qemuparamv, VALUE qemuvaluev) { guestfs_h *g; @@ -4016,6 +4037,8 @@ void Init__guestfs () ruby_guestfs_add_drive, 1); rb_define_method (c_guestfs, "add_cdrom", ruby_guestfs_add_cdrom, 1); + rb_define_method (c_guestfs, "add_drive_ro", + ruby_guestfs_add_drive_ro, 1); rb_define_method (c_guestfs, "config", ruby_guestfs_config, 2); rb_define_method (c_guestfs, "set_qemu", diff --git a/src/guestfs-actions.h b/src/guestfs-actions.h index 4364d35..2cd3bdb 100644 --- a/src/guestfs-actions.h +++ b/src/guestfs-actions.h @@ -51,6 +51,7 @@ extern int guestfs_wait_ready (guestfs_h *handle); extern int guestfs_kill_subprocess (guestfs_h *handle); extern int guestfs_add_drive (guestfs_h *handle, const char *filename); extern int guestfs_add_cdrom (guestfs_h *handle, const char *filename); +extern int guestfs_add_drive_ro (guestfs_h *handle, const char *filename); extern int guestfs_config (guestfs_h *handle, const char *qemuparam, const char *qemuvalue); extern int guestfs_set_qemu (guestfs_h *handle, const char *qemu); extern const char *guestfs_get_qemu (guestfs_h *handle); -- 1.8.3.1