diff options
author | Richard Jones <rjones@redhat.com> | 2009-04-09 13:19:38 +0100 |
---|---|---|
committer | Richard Jones <rjones@redhat.com> | 2009-04-09 13:19:38 +0100 |
commit | e7eca50046e9a69dac27c0bee832af0a3014e02c (patch) | |
tree | 0d3adfb16768d7068e180dba7cc49c706ece38f3 /ocaml | |
parent | a2e1d51acda406fd4193f121ac9f879e60cf4302 (diff) | |
download | libguestfs-e7eca50046e9a69dac27c0bee832af0a3014e02c.tar.gz libguestfs-e7eca50046e9a69dac27c0bee832af0a3014e02c.tar.xz libguestfs-e7eca50046e9a69dac27c0bee832af0a3014e02c.zip |
Added Augeas support.
Diffstat (limited to 'ocaml')
-rw-r--r-- | ocaml/guestfs.ml | 12 | ||||
-rw-r--r-- | ocaml/guestfs.mli | 36 | ||||
-rw-r--r-- | ocaml/guestfs_c_actions.c | 293 |
3 files changed, 339 insertions, 2 deletions
diff --git a/ocaml/guestfs.ml b/ocaml/guestfs.ml index 2504b45e..64878611 100644 --- a/ocaml/guestfs.ml +++ b/ocaml/guestfs.ml @@ -112,3 +112,15 @@ external pvs_full : t -> lvm_pv array = "ocaml_guestfs_pvs_full" external vgs_full : t -> lvm_vg array = "ocaml_guestfs_vgs_full" external lvs_full : t -> lvm_lv array = "ocaml_guestfs_lvs_full" external read_lines : t -> string -> string array = "ocaml_guestfs_read_lines" +external aug_init : t -> string -> int -> unit = "ocaml_guestfs_aug_init" +external aug_close : t -> unit = "ocaml_guestfs_aug_close" +external aug_defvar : t -> string -> string option -> int = "ocaml_guestfs_aug_defvar" +external aug_defnode : t -> string -> string -> string -> int * bool = "ocaml_guestfs_aug_defnode" +external aug_get : t -> string -> string = "ocaml_guestfs_aug_get" +external aug_set : t -> string -> string -> unit = "ocaml_guestfs_aug_set" +external aug_insert : t -> string -> string -> bool -> unit = "ocaml_guestfs_aug_insert" +external aug_rm : t -> string -> int = "ocaml_guestfs_aug_rm" +external aug_mv : t -> string -> string -> unit = "ocaml_guestfs_aug_mv" +external aug_match : t -> string -> string array = "ocaml_guestfs_aug_match" +external aug_save : t -> unit = "ocaml_guestfs_aug_save" +external aug_load : t -> unit = "ocaml_guestfs_aug_load" diff --git a/ocaml/guestfs.mli b/ocaml/guestfs.mli index 177f09e8..b1452abe 100644 --- a/ocaml/guestfs.mli +++ b/ocaml/guestfs.mli @@ -175,3 +175,39 @@ val lvs_full : t -> lvm_lv array val read_lines : t -> string -> string array (** read file as lines *) +val aug_init : t -> string -> int -> unit +(** create a new Augeas handle *) + +val aug_close : t -> unit +(** close the current Augeas handle *) + +val aug_defvar : t -> string -> string option -> int +(** define an Augeas variable *) + +val aug_defnode : t -> string -> string -> string -> int * bool +(** define an Augeas node *) + +val aug_get : t -> string -> string +(** look up the value of an Augeas path *) + +val aug_set : t -> string -> string -> unit +(** set Augeas path to value *) + +val aug_insert : t -> string -> string -> bool -> unit +(** insert a sibling Augeas node *) + +val aug_rm : t -> string -> int +(** remove an Augeas path *) + +val aug_mv : t -> string -> string -> unit +(** move Augeas node *) + +val aug_match : t -> string -> string array +(** return Augeas nodes which match path *) + +val aug_save : t -> unit +(** write all pending Augeas changes to disk *) + +val aug_load : t -> unit +(** load files into the tree *) + diff --git a/ocaml/guestfs_c_actions.c b/ocaml/guestfs_c_actions.c index 80a891e8..f21d63ec 100644 --- a/ocaml/guestfs_c_actions.c +++ b/ocaml/guestfs_c_actions.c @@ -456,7 +456,7 @@ ocaml_guestfs_get_autosync (value gv) if (r == -1) ocaml_guestfs_raise_error (g, "get_autosync"); - rv = r ? Val_true : Val_false; + rv = Val_bool (r); CAMLreturn (rv); } @@ -501,7 +501,7 @@ ocaml_guestfs_get_verbose (value gv) if (r == -1) ocaml_guestfs_raise_error (g, "get_verbose"); - rv = r ? Val_true : Val_false; + rv = Val_bool (r); CAMLreturn (rv); } @@ -868,3 +868,292 @@ ocaml_guestfs_read_lines (value gv, value pathv) CAMLreturn (rv); } +CAMLprim value +ocaml_guestfs_aug_init (value gv, value rootv, value flagsv) +{ + CAMLparam3 (gv, rootv, flagsv); + CAMLlocal1 (rv); + + guestfs_h *g = Guestfs_val (gv); + if (g == NULL) + caml_failwith ("aug_init: used handle after closing it"); + + const char *root = String_val (rootv); + int flags = Int_val (flagsv); + int r; + + caml_enter_blocking_section (); + r = guestfs_aug_init (g, root, flags); + caml_leave_blocking_section (); + if (r == -1) + ocaml_guestfs_raise_error (g, "aug_init"); + + rv = Val_unit; + CAMLreturn (rv); +} + +CAMLprim value +ocaml_guestfs_aug_close (value gv) +{ + CAMLparam1 (gv); + CAMLlocal1 (rv); + + guestfs_h *g = Guestfs_val (gv); + if (g == NULL) + caml_failwith ("aug_close: used handle after closing it"); + + int r; + + caml_enter_blocking_section (); + r = guestfs_aug_close (g); + caml_leave_blocking_section (); + if (r == -1) + ocaml_guestfs_raise_error (g, "aug_close"); + + rv = Val_unit; + CAMLreturn (rv); +} + +CAMLprim value +ocaml_guestfs_aug_defvar (value gv, value namev, value exprv) +{ + CAMLparam3 (gv, namev, exprv); + CAMLlocal1 (rv); + + guestfs_h *g = Guestfs_val (gv); + if (g == NULL) + caml_failwith ("aug_defvar: used handle after closing it"); + + const char *name = String_val (namev); + const char *expr = + exprv != Val_int (0) ? String_val (Field (exprv, 0)) : NULL; + int r; + + caml_enter_blocking_section (); + r = guestfs_aug_defvar (g, name, expr); + caml_leave_blocking_section (); + if (r == -1) + ocaml_guestfs_raise_error (g, "aug_defvar"); + + rv = Val_int (r); + CAMLreturn (rv); +} + +CAMLprim value +ocaml_guestfs_aug_defnode (value gv, value namev, value exprv, value valv) +{ + CAMLparam4 (gv, namev, exprv, valv); + CAMLlocal1 (rv); + + guestfs_h *g = Guestfs_val (gv); + if (g == NULL) + caml_failwith ("aug_defnode: used handle after closing it"); + + const char *name = String_val (namev); + const char *expr = String_val (exprv); + const char *val = String_val (valv); + struct guestfs_int_bool *r; + + caml_enter_blocking_section (); + r = guestfs_aug_defnode (g, name, expr, val); + caml_leave_blocking_section (); + if (r == NULL) + ocaml_guestfs_raise_error (g, "aug_defnode"); + + rv = caml_alloc (2, 0); + Store_field (rv, 0, Val_int (r->i)); + Store_field (rv, 1, Val_bool (r->b)); + guestfs_free_int_bool (r); + CAMLreturn (rv); +} + +CAMLprim value +ocaml_guestfs_aug_get (value gv, value pathv) +{ + CAMLparam2 (gv, pathv); + CAMLlocal1 (rv); + + guestfs_h *g = Guestfs_val (gv); + if (g == NULL) + caml_failwith ("aug_get: used handle after closing it"); + + const char *path = String_val (pathv); + char *r; + + caml_enter_blocking_section (); + r = guestfs_aug_get (g, path); + caml_leave_blocking_section (); + if (r == NULL) + ocaml_guestfs_raise_error (g, "aug_get"); + + rv = caml_copy_string (r); + free (r); + CAMLreturn (rv); +} + +CAMLprim value +ocaml_guestfs_aug_set (value gv, value pathv, value valv) +{ + CAMLparam3 (gv, pathv, valv); + CAMLlocal1 (rv); + + guestfs_h *g = Guestfs_val (gv); + if (g == NULL) + caml_failwith ("aug_set: used handle after closing it"); + + const char *path = String_val (pathv); + const char *val = String_val (valv); + int r; + + caml_enter_blocking_section (); + r = guestfs_aug_set (g, path, val); + caml_leave_blocking_section (); + if (r == -1) + ocaml_guestfs_raise_error (g, "aug_set"); + + rv = Val_unit; + CAMLreturn (rv); +} + +CAMLprim value +ocaml_guestfs_aug_insert (value gv, value pathv, value labelv, value beforev) +{ + CAMLparam4 (gv, pathv, labelv, beforev); + CAMLlocal1 (rv); + + guestfs_h *g = Guestfs_val (gv); + if (g == NULL) + caml_failwith ("aug_insert: used handle after closing it"); + + const char *path = String_val (pathv); + const char *label = String_val (labelv); + int before = Bool_val (beforev); + int r; + + caml_enter_blocking_section (); + r = guestfs_aug_insert (g, path, label, before); + caml_leave_blocking_section (); + if (r == -1) + ocaml_guestfs_raise_error (g, "aug_insert"); + + rv = Val_unit; + CAMLreturn (rv); +} + +CAMLprim value +ocaml_guestfs_aug_rm (value gv, value pathv) +{ + CAMLparam2 (gv, pathv); + CAMLlocal1 (rv); + + guestfs_h *g = Guestfs_val (gv); + if (g == NULL) + caml_failwith ("aug_rm: used handle after closing it"); + + const char *path = String_val (pathv); + int r; + + caml_enter_blocking_section (); + r = guestfs_aug_rm (g, path); + caml_leave_blocking_section (); + if (r == -1) + ocaml_guestfs_raise_error (g, "aug_rm"); + + rv = Val_int (r); + CAMLreturn (rv); +} + +CAMLprim value +ocaml_guestfs_aug_mv (value gv, value srcv, value destv) +{ + CAMLparam3 (gv, srcv, destv); + CAMLlocal1 (rv); + + guestfs_h *g = Guestfs_val (gv); + if (g == NULL) + caml_failwith ("aug_mv: used handle after closing it"); + + const char *src = String_val (srcv); + const char *dest = String_val (destv); + int r; + + caml_enter_blocking_section (); + r = guestfs_aug_mv (g, src, dest); + caml_leave_blocking_section (); + if (r == -1) + ocaml_guestfs_raise_error (g, "aug_mv"); + + rv = Val_unit; + CAMLreturn (rv); +} + +CAMLprim value +ocaml_guestfs_aug_match (value gv, value pathv) +{ + CAMLparam2 (gv, pathv); + CAMLlocal1 (rv); + + guestfs_h *g = Guestfs_val (gv); + if (g == NULL) + caml_failwith ("aug_match: used handle after closing it"); + + const char *path = String_val (pathv); + int i; + char **r; + + caml_enter_blocking_section (); + r = guestfs_aug_match (g, path); + caml_leave_blocking_section (); + if (r == NULL) + ocaml_guestfs_raise_error (g, "aug_match"); + + rv = caml_copy_string_array ((const char **) r); + for (i = 0; r[i] != NULL; ++i) free (r[i]); + free (r); + CAMLreturn (rv); +} + +CAMLprim value +ocaml_guestfs_aug_save (value gv) +{ + CAMLparam1 (gv); + CAMLlocal1 (rv); + + guestfs_h *g = Guestfs_val (gv); + if (g == NULL) + caml_failwith ("aug_save: used handle after closing it"); + + int r; + + caml_enter_blocking_section (); + r = guestfs_aug_save (g); + caml_leave_blocking_section (); + if (r == -1) + ocaml_guestfs_raise_error (g, "aug_save"); + + rv = Val_unit; + CAMLreturn (rv); +} + +CAMLprim value +ocaml_guestfs_aug_load (value gv) +{ + CAMLparam1 (gv); + CAMLlocal1 (rv); + + guestfs_h *g = Guestfs_val (gv); + if (g == NULL) + caml_failwith ("aug_load: used handle after closing it"); + + int r; + + caml_enter_blocking_section (); + r = guestfs_aug_load (g); + caml_leave_blocking_section (); + if (r == -1) + ocaml_guestfs_raise_error (g, "aug_load"); + + rv = Val_unit; + CAMLreturn (rv); +} + |