summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Jones <rjones@redhat.com>2009-04-03 01:15:17 +0100
committerRichard Jones <rjones@redhat.com>2009-04-03 01:15:17 +0100
commit8d0068a752ee8e6bc223de5cb7cac5d190a8855e (patch)
tree61246e4ab660bbc1531bb0853c501ef32b3f6fc7
parent15dbb6973a7af11b81df047194228ea86d46939b (diff)
downloadlibguestfs-8d0068a752ee8e6bc223de5cb7cac5d190a8855e.tar.gz
libguestfs-8d0068a752ee8e6bc223de5cb7cac5d190a8855e.tar.xz
libguestfs-8d0068a752ee8e6bc223de5cb7cac5d190a8855e.zip
Start the generated code and code generator.
-rw-r--r--README5
-rw-r--r--guestfs-actions.pod33
-rw-r--r--guestfs.pod33
-rwxr-xr-xsrc/generator.ml184
-rw-r--r--src/guestfs.c3
-rw-r--r--src/guestfs_protocol.x19
6 files changed, 236 insertions, 41 deletions
diff --git a/README b/README
index 05bb3501..0cf9c4f5 100644
--- a/README
+++ b/README
@@ -36,6 +36,11 @@ Requirements
- XDR, rpcgen
+- (Optional) perldoc to generate the manual pages
+
+- (Optional) OCaml if you want to modify the code or rebuild certain
+generated files.
+
- (Optional) local Fedora mirror
Running ./configure will check you have all the requirements installed
diff --git a/guestfs-actions.pod b/guestfs-actions.pod
new file mode 100644
index 00000000..0eb24838
--- /dev/null
+++ b/guestfs-actions.pod
@@ -0,0 +1,33 @@
+=head2 guestfs_mount
+
+ int guestfs_mount (guestfs_h *handle, const char *device, const char *mountpoint);
+
+Mount a guest disk at a position in the filesystem. Block devices
+are named C</dev/sda>, C</dev/sdb> and so on, as they were added to
+the guest. If those block devices contain partitions, they will have
+the usual names (eg. C</dev/sda1>). Also LVM C</dev/VG/LV>-style
+names can be used.
+
+The rules are the same as for L<mount(2)>: A filesystem must
+first be mounted on C</> before others can be mounted. Other
+filesystems can only be mounted on directories which already
+exist.
+
+=head2 guestfs_sync
+
+ int guestfs_sync (guestfs_h *handle);
+
+This syncs the disk, so that any writes are flushed through to the
+underlying disk image.
+
+You should always call this if you have modified a disk image, before
+calling C<guestfs_close>.
+
+=head2 guestfs_touch
+
+ int guestfs_touch (guestfs_h *handle, const char *path);
+
+Touch acts like the L<touch(1)> command. It can be used to
+update the filesystems on a file, or, if the file does not exist,
+to create a new zero-length file.
+
diff --git a/guestfs.pod b/guestfs.pod
index b0fa5f29..829e6e55 100644
--- a/guestfs.pod
+++ b/guestfs.pod
@@ -257,40 +257,7 @@ This returns the verbose messages flag.
=head1 HIGH-LEVEL API ACTIONS
-=head2 guestfs_sync
- int guestfs_sync (guestfs_h *handle);
-
-This syncs the disk, so that any writes are flushed through to the
-underlying disk image.
-
-You should always call this if you have modified a disk image, before
-calling C<guestfs_close>.
-
-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
-
-Documentation will be auto-generated from here, including for
-guestfs_sync.
-
-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
-
- do_[action] ([parameters])
- {
- guestfs_set_reply_callback (handle, [action]_cb, data);
- guestfs_nb_[action] (handle, [parameters ...]);
-
- guestfs_main_loop_run (); /* --> blocks, then calls my_cb */
- }
-
- [action]_cb (guestfs_h *handle, void *data)
- {
- retval = guestfs_nb_[action]_r (handle);
- /* ... */
- guestfs_main_loop_quit ();
- return retval;
- }
-
-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
diff --git a/src/generator.ml b/src/generator.ml
new file mode 100755
index 00000000..02fe6912
--- /dev/null
+++ b/src/generator.ml
@@ -0,0 +1,184 @@
+#!/usr/bin/ocamlrun ocaml
+(* libguestfs
+ * Copyright (C) 2009 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * This script generates a large amount of code and documentation for
+ * all the daemon actions. To add a new action there are only two
+ * files you need to change, this one to describe the interface, and
+ * daemon/<somefile>.c to write the implementation.
+ *)
+
+#load "unix.cma";;
+
+open Printf
+
+type styles =
+ | Int_Void (* int foo (guestfs_h); *)
+ | Int_String (* int foo (guestfs_h, const char * ); *)
+ | Int_StringString (* int foo (guestfs_h, const char *, const char * ); *)
+
+let functions = [
+ ("mount", Int_StringString, [|"device"; "mountpoint"|],
+ "Mount a guest disk at a position in the filesystem",
+ "\
+Mount a guest disk at a position in the filesystem. Block devices
+are named C</dev/sda>, C</dev/sdb> and so on, as they were added to
+the guest. If those block devices contain partitions, they will have
+the usual names (eg. C</dev/sda1>). Also LVM C</dev/VG/LV>-style
+names can be used.
+
+The rules are the same as for L<mount(2)>: A filesystem must
+first be mounted on C</> before others can be mounted. Other
+filesystems can only be mounted on directories which already
+exist.");
+
+ ("sync", Int_Void, [||],
+ "Sync disks, writes are flushed through to the disk image",
+ "\
+This syncs the disk, so that any writes are flushed through to the
+underlying disk image.
+
+You should always call this if you have modified a disk image, before
+calling C<guestfs_close>.");
+
+ ("touch", Int_String, [|"path"|],
+ "Update file timestamps or create a new file",
+ "\
+Touch acts like the L<touch(1)> command. It can be used to
+update the filesystems on a file, or, if the file does not exist,
+to create a new zero-length file.");
+]
+
+(* 'pr' prints to the current output file. *)
+let chan = ref stdout
+let pr fs = ksprintf (output_string !chan) fs
+
+type comment_style = CStyle | HashStyle | OCamlStyle
+type license = GPLv2 | LGPLv2
+
+(* Generate a header block in a number of standard styles. *)
+let rec generate_header comment license =
+ let c = match comment with
+ | CStyle -> pr "/* "; " *"
+ | HashStyle -> pr "# "; "#"
+ | OCamlStyle -> pr "(* "; " *" in
+ pr "libguestfs generated file\n";
+ pr "%s WARNING: This file is generated by 'src/generator.ml'.\n" c;
+ pr "%s Any changes you make to this file will be lost.\n" c;
+ pr "%s\n" c;
+ pr "%s Copyright (C) 2009 Red Hat Inc.\n" c;
+ pr "%s\n" c;
+ (match license with
+ | GPLv2 ->
+ pr "%s This program is free software; you can redistribute it and/or modify\n" c;
+ pr "%s it under the terms of the GNU General Public License as published by\n" c;
+ pr "%s the Free Software Foundation; either version 2 of the License, or\n" c;
+ pr "%s (at your option) any later version.\n" c;
+ pr "%s\n" c;
+ pr "%s This program is distributed in the hope that it will be useful,\n" c;
+ pr "%s but WITHOUT ANY WARRANTY; without even the implied warranty of\n" c;
+ pr "%s MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" c;
+ pr "%s GNU General Public License for more details.\n" c;
+ pr "%s\n" c;
+ pr "%s You should have received a copy of the GNU General Public License along\n" c;
+ pr "%s with this program; if not, write to the Free Software Foundation, Inc.,\n" c;
+ pr "%s 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n" c;
+
+ | LGPLv2 ->
+ pr "%s This library is free software; you can redistribute it and/or\n" c;
+ pr "%s modify it under the terms of the GNU Lesser General Public\n" c;
+ pr "%s License as published by the Free Software Foundation; either\n" c;
+ pr "%s version 2 of the License, or (at your option) any later version.\n" c;
+ pr "%s\n" c;
+ pr "%s This library is distributed in the hope that it will be useful,\n" c;
+ pr "%s but WITHOUT ANY WARRANTY; without even the implied warranty of\n" c;
+ pr "%s MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n" c;
+ pr "%s Lesser General Public License for more details.\n" c;
+ pr "%s\n" c;
+ pr "%s You should have received a copy of the GNU Lesser General Public\n" c;
+ pr "%s License along with this library; if not, write to the Free Software\n" c;
+ pr "%s Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n" c;
+ );
+ (match comment with
+ | CStyle -> pr " */\n"
+ | HashStyle -> ()
+ | OCamlStyle -> pr " *)\n"
+ );
+ pr "\n"
+
+(* Generate the pod documentation for the C API. *)
+and generate_pod () =
+ List.iter (
+ fun (shortname, style, params, _, longdesc) ->
+ let name = "guestfs_" ^ shortname in
+ pr "=head2 %s\n\n" name;
+ pr " ";
+ generate_prototype ~extern:false name style params;
+ pr "\n\n";
+ pr "%s\n\n" longdesc
+ ) functions
+
+(* Generate the protocol (XDR) file. *)
+and generate_xdr () =
+ generate_header CStyle LGPLv2;
+ List.iter (
+ fun (shortname, style, params, _, longdesc) ->
+ let name = "guestfs_" ^ shortname in
+ pr "/* %s */\n" name;
+
+
+ pr "\n";
+ ) functions
+
+(* Generate a single line prototype. *)
+and generate_prototype ~extern ?(semi = true) ?(handle = "handle")
+ name style params =
+ if extern then pr "extern ";
+ (match style with
+ | Int_Void | Int_String | Int_StringString -> pr "int "
+ );
+ pr "%s (guestfs_h *%s" name handle;
+ (match style with
+ | Int_Void -> ()
+ | Int_String ->
+ pr ", const char *%s" params.(0)
+ | Int_StringString ->
+ pr ", const char *%s" params.(0);
+ pr ", const char *%s" params.(1)
+ );
+ pr ")";
+ if semi then pr ";"
+
+let output_to filename =
+ let filename_new = filename ^ ".new" in
+ chan := open_out filename_new;
+ let close () =
+ close_out !chan;
+ chan := stdout;
+ Unix.rename filename_new filename
+ in
+ close
+
+(* Main program. *)
+let () =
+ let close = output_to "guestfs-actions.pod" in
+ generate_pod ();
+ close ();
+
+ let close = output_to "src/guestfs_protocol.x" in
+ generate_xdr ();
+ close ();
diff --git a/src/guestfs.c b/src/guestfs.c
index ea86f1ba..bbcf7a69 100644
--- a/src/guestfs.c
+++ b/src/guestfs.c
@@ -75,6 +75,7 @@ static void select_main_loop_quit (guestfs_h *g);
#define UNIX_PATH_MAX 108
+/* Also in guestfsd.c */
#define VMCHANNEL_PORT 6666
#define VMCHANNEL_ADDR "10.0.2.4"
@@ -833,7 +834,7 @@ sock_read_event (void *data, int watch, int fd, int events)
* starts up it sends a "magic" value (longer than any possible
* message). Check for this.
*/
- if (len == 0xf5f5f5f5) {
+ if (len == 0xf5f55ff5) {
if (g->state != LAUNCHING)
error (g, "received magic signature from guestfsd, but in state %d",
g->state);
diff --git a/src/guestfs_protocol.x b/src/guestfs_protocol.x
index 59bad589..bf83325e 100644
--- a/src/guestfs_protocol.x
+++ b/src/guestfs_protocol.x
@@ -1,5 +1,8 @@
-/* libguestfs
- * Copyright (C) 2009 Red Hat Inc.
+/* libguestfs generated file
+ * WARNING: This file is generated by 'src/generator.ml'.
+ * Any changes you make to this file will be lost.
+ *
+ * Copyright (C) 2009 Red Hat Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -14,9 +17,11 @@
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * This file describes the client [library] to server [daemon in
- * guest] protocol. As far as possible, all code in the library is
- * automatically generated from this protocol description using
- * rpcgen and the perl script 'generator.pl'.
*/
+
+/* guestfs_mount */
+
+/* guestfs_sync */
+
+/* guestfs_touch */
+