+static CAMLprim value
+copy_lvm_pv (const struct guestfs_lvm_pv *pv)
+{
+ CAMLparam0 ();
+ CAMLlocal2 (rv, v);
+
+ rv = caml_alloc (14, 0);
+ v = caml_copy_string (pv->pv_name);
+ Store_field (rv, 0, v);
+ v = caml_alloc_string (32);
+ memcpy (String_val (v), pv->pv_uuid, 32);
+ Store_field (rv, 1, v);
+ v = caml_copy_string (pv->pv_fmt);
+ Store_field (rv, 2, v);
+ v = caml_copy_int64 (pv->pv_size);
+ Store_field (rv, 3, v);
+ v = caml_copy_int64 (pv->dev_size);
+ Store_field (rv, 4, v);
+ v = caml_copy_int64 (pv->pv_free);
+ Store_field (rv, 5, v);
+ v = caml_copy_int64 (pv->pv_used);
+ Store_field (rv, 6, v);
+ v = caml_copy_string (pv->pv_attr);
+ Store_field (rv, 7, v);
+ v = caml_copy_int64 (pv->pv_pe_count);
+ Store_field (rv, 8, v);
+ v = caml_copy_int64 (pv->pv_pe_alloc_count);
+ Store_field (rv, 9, v);
+ v = caml_copy_string (pv->pv_tags);
+ Store_field (rv, 10, v);
+ v = caml_copy_int64 (pv->pe_start);
+ Store_field (rv, 11, v);
+ v = caml_copy_int64 (pv->pv_mda_count);
+ Store_field (rv, 12, v);
+ v = caml_copy_int64 (pv->pv_mda_free);
+ Store_field (rv, 13, v);
+ CAMLreturn (rv);
+}
+
+static CAMLprim value
+copy_lvm_pv_list (const struct guestfs_lvm_pv_list *pvs)
+{
+ CAMLparam0 ();
+ CAMLlocal2 (rv, v);
+ int i;
+
+ if (pvs->len == 0)
+ CAMLreturn (Atom (0));
+ else {
+ rv = caml_alloc (pvs->len, 0);
+ for (i = 0; i < pvs->len; ++i) {
+ v = copy_lvm_pv (&pvs->val[i]);
+ caml_modify (&Field (rv, i), v);
+ }
+ CAMLreturn (rv);
+ }
+}
+
+static CAMLprim value
+copy_lvm_vg (const struct guestfs_lvm_vg *vg)
+{
+ CAMLparam0 ();
+ CAMLlocal2 (rv, v);
+
+ rv = caml_alloc (19, 0);
+ v = caml_copy_string (vg->vg_name);
+ Store_field (rv, 0, v);
+ v = caml_alloc_string (32);
+ memcpy (String_val (v), vg->vg_uuid, 32);
+ Store_field (rv, 1, v);
+ v = caml_copy_string (vg->vg_fmt);
+ Store_field (rv, 2, v);
+ v = caml_copy_string (vg->vg_attr);
+ Store_field (rv, 3, v);
+ v = caml_copy_int64 (vg->vg_size);
+ Store_field (rv, 4, v);
+ v = caml_copy_int64 (vg->vg_free);
+ Store_field (rv, 5, v);
+ v = caml_copy_string (vg->vg_sysid);
+ Store_field (rv, 6, v);
+ v = caml_copy_int64 (vg->vg_extent_size);
+ Store_field (rv, 7, v);
+ v = caml_copy_int64 (vg->vg_extent_count);
+ Store_field (rv, 8, v);
+ v = caml_copy_int64 (vg->vg_free_count);
+ Store_field (rv, 9, v);
+ v = caml_copy_int64 (vg->max_lv);
+ Store_field (rv, 10, v);
+ v = caml_copy_int64 (vg->max_pv);
+ Store_field (rv, 11, v);
+ v = caml_copy_int64 (vg->pv_count);
+ Store_field (rv, 12, v);
+ v = caml_copy_int64 (vg->lv_count);
+ Store_field (rv, 13, v);
+ v = caml_copy_int64 (vg->snap_count);
+ Store_field (rv, 14, v);
+ v = caml_copy_int64 (vg->vg_seqno);
+ Store_field (rv, 15, v);
+ v = caml_copy_string (vg->vg_tags);
+ Store_field (rv, 16, v);
+ v = caml_copy_int64 (vg->vg_mda_count);
+ Store_field (rv, 17, v);
+ v = caml_copy_int64 (vg->vg_mda_free);
+ Store_field (rv, 18, v);
+ CAMLreturn (rv);
+}
+
+static CAMLprim value
+copy_lvm_vg_list (const struct guestfs_lvm_vg_list *vgs)
+{
+ CAMLparam0 ();
+ CAMLlocal2 (rv, v);
+ int i;
+
+ if (vgs->len == 0)
+ CAMLreturn (Atom (0));
+ else {
+ rv = caml_alloc (vgs->len, 0);
+ for (i = 0; i < vgs->len; ++i) {
+ v = copy_lvm_vg (&vgs->val[i]);
+ caml_modify (&Field (rv, i), v);
+ }
+ CAMLreturn (rv);
+ }
+}
+
+static CAMLprim value
+copy_lvm_lv (const struct guestfs_lvm_lv *lv)
+{
+ CAMLparam0 ();
+ CAMLlocal3 (rv, v, v2);
+
+ rv = caml_alloc (16, 0);
+ v = caml_copy_string (lv->lv_name);
+ Store_field (rv, 0, v);
+ v = caml_alloc_string (32);
+ memcpy (String_val (v), lv->lv_uuid, 32);
+ Store_field (rv, 1, v);
+ v = caml_copy_string (lv->lv_attr);
+ Store_field (rv, 2, v);
+ v = caml_copy_int64 (lv->lv_major);
+ Store_field (rv, 3, v);
+ v = caml_copy_int64 (lv->lv_minor);
+ Store_field (rv, 4, v);
+ v = caml_copy_int64 (lv->lv_kernel_major);
+ Store_field (rv, 5, v);
+ v = caml_copy_int64 (lv->lv_kernel_minor);
+ Store_field (rv, 6, v);
+ v = caml_copy_int64 (lv->lv_size);
+ Store_field (rv, 7, v);
+ v = caml_copy_int64 (lv->seg_count);
+ Store_field (rv, 8, v);
+ v = caml_copy_string (lv->origin);
+ Store_field (rv, 9, v);
+ if (lv->snap_percent >= 0) { /* Some snap_percent */
+ v2 = caml_copy_double (lv->snap_percent);
+ v = caml_alloc (1, 0);
+ Store_field (v, 0, v2);
+ } else /* None */
+ v = Val_int (0);
+ Store_field (rv, 10, v);
+ if (lv->copy_percent >= 0) { /* Some copy_percent */
+ v2 = caml_copy_double (lv->copy_percent);
+ v = caml_alloc (1, 0);
+ Store_field (v, 0, v2);
+ } else /* None */
+ v = Val_int (0);
+ Store_field (rv, 11, v);
+ v = caml_copy_string (lv->move_pv);
+ Store_field (rv, 12, v);
+ v = caml_copy_string (lv->lv_tags);
+ Store_field (rv, 13, v);
+ v = caml_copy_string (lv->mirror_log);
+ Store_field (rv, 14, v);
+ v = caml_copy_string (lv->modules);
+ Store_field (rv, 15, v);
+ CAMLreturn (rv);
+}
+
+static CAMLprim value
+copy_lvm_lv_list (const struct guestfs_lvm_lv_list *lvs)
+{
+ CAMLparam0 ();
+ CAMLlocal2 (rv, v);
+ int i;
+
+ if (lvs->len == 0)
+ CAMLreturn (Atom (0));
+ else {
+ rv = caml_alloc (lvs->len, 0);
+ for (i = 0; i < lvs->len; ++i) {
+ v = copy_lvm_lv (&lvs->val[i]);
+ caml_modify (&Field (rv, i), v);
+ }
+ CAMLreturn (rv);
+ }
+}
+
+CAMLprim value
+ocaml_guestfs_launch (value gv)
+{
+ CAMLparam1 (gv);
+ CAMLlocal1 (rv);
+
+ guestfs_h *g = Guestfs_val (gv);
+ if (g == NULL)
+ caml_failwith ("launch: used handle after closing it");
+
+ int r;
+
+ caml_enter_blocking_section ();
+ r = guestfs_launch (g);
+ caml_leave_blocking_section ();
+ if (r == -1)
+ ocaml_guestfs_raise_error (g, "launch");
+
+ rv = Val_unit;
+ CAMLreturn (rv);
+}
+
+CAMLprim value
+ocaml_guestfs_wait_ready (value gv)
+{
+ CAMLparam1 (gv);
+ CAMLlocal1 (rv);
+
+ guestfs_h *g = Guestfs_val (gv);
+ if (g == NULL)
+ caml_failwith ("wait_ready: used handle after closing it");
+
+ int r;
+
+ caml_enter_blocking_section ();
+ r = guestfs_wait_ready (g);
+ caml_leave_blocking_section ();
+ if (r == -1)
+ ocaml_guestfs_raise_error (g, "wait_ready");
+
+ rv = Val_unit;
+ CAMLreturn (rv);
+}
+
+CAMLprim value
+ocaml_guestfs_kill_subprocess (value gv)
+{
+ CAMLparam1 (gv);
+ CAMLlocal1 (rv);
+
+ guestfs_h *g = Guestfs_val (gv);
+ if (g == NULL)
+ caml_failwith ("kill_subprocess: used handle after closing it");
+
+ int r;
+
+ caml_enter_blocking_section ();
+ r = guestfs_kill_subprocess (g);
+ caml_leave_blocking_section ();
+ if (r == -1)
+ ocaml_guestfs_raise_error (g, "kill_subprocess");
+
+ rv = Val_unit;
+ CAMLreturn (rv);
+}
+
+CAMLprim value
+ocaml_guestfs_add_drive (value gv, value filenamev)
+{
+ CAMLparam2 (gv, filenamev);
+ CAMLlocal1 (rv);
+
+ guestfs_h *g = Guestfs_val (gv);
+ if (g == NULL)
+ caml_failwith ("add_drive: used handle after closing it");
+
+ const char *filename = String_val (filenamev);
+ int r;
+
+ caml_enter_blocking_section ();
+ r = guestfs_add_drive (g, filename);
+ caml_leave_blocking_section ();
+ if (r == -1)
+ ocaml_guestfs_raise_error (g, "add_drive");
+
+ rv = Val_unit;
+ CAMLreturn (rv);
+}
+
+CAMLprim value
+ocaml_guestfs_add_cdrom (value gv, value filenamev)
+{
+ CAMLparam2 (gv, filenamev);
+ CAMLlocal1 (rv);
+
+ guestfs_h *g = Guestfs_val (gv);
+ if (g == NULL)
+ caml_failwith ("add_cdrom: used handle after closing it");
+
+ const char *filename = String_val (filenamev);
+ int r;
+
+ caml_enter_blocking_section ();
+ r = guestfs_add_cdrom (g, filename);
+ caml_leave_blocking_section ();
+ if (r == -1)
+ ocaml_guestfs_raise_error (g, "add_cdrom");
+
+ rv = Val_unit;
+ CAMLreturn (rv);
+}
+
+CAMLprim value
+ocaml_guestfs_config (value gv, value qemuparamv, value qemuvaluev)
+{
+ CAMLparam3 (gv, qemuparamv, qemuvaluev);
+ CAMLlocal1 (rv);
+
+ guestfs_h *g = Guestfs_val (gv);
+ if (g == NULL)
+ caml_failwith ("config: used handle after closing it");
+
+ const char *qemuparam = String_val (qemuparamv);
+ const char *qemuvalue =
+ qemuvaluev != Val_int (0) ? String_val (Field (qemuvaluev, 0)) : NULL;
+ int r;
+
+ caml_enter_blocking_section ();
+ r = guestfs_config (g, qemuparam, qemuvalue);
+ caml_leave_blocking_section ();
+ if (r == -1)
+ ocaml_guestfs_raise_error (g, "config");
+
+ rv = Val_unit;
+ CAMLreturn (rv);
+}
+
+CAMLprim value
+ocaml_guestfs_set_path (value gv, value pathv)
+{
+ CAMLparam2 (gv, pathv);
+ CAMLlocal1 (rv);
+
+ guestfs_h *g = Guestfs_val (gv);
+ if (g == NULL)
+ caml_failwith ("set_path: used handle after closing it");
+
+ const char *path = String_val (pathv);
+ int r;
+
+ caml_enter_blocking_section ();
+ r = guestfs_set_path (g, path);
+ caml_leave_blocking_section ();
+ if (r == -1)
+ ocaml_guestfs_raise_error (g, "set_path");
+
+ rv = Val_unit;
+ CAMLreturn (rv);
+}
+
+CAMLprim value
+ocaml_guestfs_get_path (value gv)
+{
+ CAMLparam1 (gv);
+ CAMLlocal1 (rv);
+
+ guestfs_h *g = Guestfs_val (gv);
+ if (g == NULL)
+ caml_failwith ("get_path: used handle after closing it");
+
+ const char *r;
+
+ caml_enter_blocking_section ();
+ r = guestfs_get_path (g);
+ caml_leave_blocking_section ();
+ if (r == NULL)
+ ocaml_guestfs_raise_error (g, "get_path");
+
+ rv = caml_copy_string (r);
+ CAMLreturn (rv);
+}
+
+CAMLprim value
+ocaml_guestfs_set_autosync (value gv, value autosyncv)
+{
+ CAMLparam2 (gv, autosyncv);
+ CAMLlocal1 (rv);
+
+ guestfs_h *g = Guestfs_val (gv);
+ if (g == NULL)
+ caml_failwith ("set_autosync: used handle after closing it");
+
+ int autosync = Bool_val (autosyncv);
+ int r;
+
+ caml_enter_blocking_section ();
+ r = guestfs_set_autosync (g, autosync);
+ caml_leave_blocking_section ();
+ if (r == -1)
+ ocaml_guestfs_raise_error (g, "set_autosync");
+
+ rv = Val_unit;
+ CAMLreturn (rv);
+}
+
+CAMLprim value
+ocaml_guestfs_get_autosync (value gv)
+{
+ CAMLparam1 (gv);
+ CAMLlocal1 (rv);
+
+ guestfs_h *g = Guestfs_val (gv);
+ if (g == NULL)
+ caml_failwith ("get_autosync: used handle after closing it");
+
+ int r;
+
+ caml_enter_blocking_section ();
+ r = guestfs_get_autosync (g);
+ caml_leave_blocking_section ();
+ if (r == -1)
+ ocaml_guestfs_raise_error (g, "get_autosync");
+
+ rv = r ? Val_true : Val_false;
+ CAMLreturn (rv);
+}
+