2 * Copyright (C) 2009-2011 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 (* Please read generator/README first. *)
26 open Generator_docstrings
27 open Generator_api_versions
28 open Generator_optgroups
29 open Generator_actions
30 open Generator_structs
35 type optarg_proto = Dots | VA | Argv
37 (* Generate a C function prototype. *)
38 let rec generate_prototype ?(extern = true) ?(static = false)
40 ?(single_line = false) ?(indent = "") ?(newline = false)
42 ?(prefix = "") ?(suffix = "")
44 ?(optarg_proto = Dots)
45 name (ret, args, optargs) =
47 if extern then pr "extern ";
48 if static then pr "static ";
54 if single_line then pr " " else pr "\n%s" indent
57 if single_line then pr " " else pr "\n%s" indent
58 | RConstString _ | RConstOptString _ ->
60 if not single_line then pr "\n%s" indent
61 | RString _ | RBufferOut _ ->
63 if not single_line then pr "\n%s" indent
64 | RStringList _ | RHashtable _ ->
66 if not single_line then pr "\n%s" indent
68 if not in_daemon then pr "struct guestfs_%s *" typ
69 else pr "guestfs_int_%s *" typ;
70 if not single_line then pr "\n%s" indent
71 | RStructList (_, typ) ->
72 if not in_daemon then pr "struct guestfs_%s_list *" typ
73 else pr "guestfs_int_%s_list *" typ;
74 if not single_line then pr "\n%s" indent
76 let is_RBufferOut = match ret with RBufferOut _ -> true | _ -> false in
77 pr "%s%s%s (" prefix name suffix;
78 if handle = None && args = [] && optargs = [] && not is_RBufferOut then
81 let comma = ref false in
84 | Some handle -> pr "guestfs_h *%s" handle; comma := true
88 if single_line then pr ", "
90 let namelen = String.length prefix + String.length name +
91 String.length suffix + 2 in
92 pr ",\n%s%s" indent (spaces namelen)
100 | Device n | Dev_or_Path n
105 pr "const char *%s" n
106 | StringList n | DeviceList n ->
108 pr "char *const *%s" n
109 | Bool n -> next (); pr "int %s" n
110 | Int n -> next (); pr "int %s" n
111 | Int64 n -> next (); pr "int64_t %s" n
114 if not in_daemon then (next (); pr "const char *%s" n)
117 pr "const char *%s" n;
119 pr "size_t %s_size" n
124 if is_RBufferOut then (next (); pr "size_t *size_r");
125 if optargs <> [] then (
127 match optarg_proto with
129 | VA -> pr "va_list args"
130 | Argv -> pr "const struct guestfs_%s_argv *optargs" name
134 if semicolon then pr ";";
135 if newline then pr "\n"
137 (* Generate C call arguments, eg "(handle, foo, bar)" *)
138 and generate_c_call_args ?handle ?(implicit_size_ptr = "&size")
139 (ret, args, optargs) =
141 let comma = ref false in
143 if !comma then pr ", ";
148 | Some handle -> pr "%s" handle; comma := true
157 pr "%s" (name_of_argt arg)
159 (* For RBufferOut calls, add implicit size pointer parameter. *)
163 pr "%s" implicit_size_ptr
166 (* For calls with optional arguments, add implicit optargs parameter. *)
167 if optargs <> [] then (
173 (* Generate the pod documentation for the C API. *)
174 and generate_actions_pod () =
176 fun (shortname, (ret, args, optargs as style), _, flags, _, _, longdesc) ->
177 if not (List.mem NotInDocs flags) then (
178 let name = "guestfs_" ^ shortname in
179 pr "=head2 %s\n\n" name;
180 generate_prototype ~extern:false ~indent:" " ~handle:"g" name style;
183 (match deprecation_notice ~prefix:"guestfs_" flags with
185 | Some txt -> pr "%s\n\n" txt
188 let uc_shortname = String.uppercase shortname in
189 if optargs <> [] then (
190 pr "You may supply a list of optional arguments to this call.\n";
191 pr "Use zero or more of the following pairs of parameters,\n";
192 pr "and terminate the list with C<-1> on its own.\n";
193 pr "See L</CALLS WITH OPTIONAL ARGUMENTS>.\n\n";
196 let n = name_of_argt argt in
197 let uc_n = String.uppercase n in
198 pr " GUESTFS_%s_%s, " uc_shortname uc_n;
200 | Bool n -> pr "int %s,\n" n
201 | Int n -> pr "int %s,\n" n
202 | Int64 n -> pr "int64_t %s,\n" n
203 | String n -> pr "const char *%s,\n" n
209 pr "%s\n\n" longdesc;
210 let ret, args, optargs = style in
213 pr "This function returns 0 on success or -1 on error.\n\n"
215 pr "On error this function returns -1.\n\n"
217 pr "On error this function returns -1.\n\n"
219 pr "This function returns a C truth value on success or -1 on error.\n\n"
221 pr "This function returns a string, or NULL on error.
222 The string is owned by the guest handle and must I<not> be freed.\n\n"
223 | RConstOptString _ ->
224 pr "This function returns a string which may be NULL.
225 There is no way to return an error from this function.
226 The string is owned by the guest handle and must I<not> be freed.\n\n"
228 pr "This function returns a string, or NULL on error.
229 I<The caller must free the returned string after use>.\n\n"
231 pr "This function returns a NULL-terminated array of strings
232 (like L<environ(3)>), or NULL if there was an error.
233 I<The caller must free the strings and the array after use>.\n\n"
234 | RStruct (_, typ) ->
235 pr "This function returns a C<struct guestfs_%s *>,
236 or NULL if there was an error.
237 I<The caller must call C<guestfs_free_%s> after use>.\n\n" typ typ
238 | RStructList (_, typ) ->
239 pr "This function returns a C<struct guestfs_%s_list *>,
240 or NULL if there was an error.
241 I<The caller must call C<guestfs_free_%s_list> after use>.\n\n" typ typ
243 pr "This function returns a NULL-terminated array of
244 strings, or NULL if there was an error.
245 The array of strings will always have length C<2n+1>, where
246 C<n> keys and values alternate, followed by the trailing NULL entry.
247 I<The caller must free the strings and the array after use>.\n\n"
249 pr "This function returns a buffer, or NULL on error.
250 The size of the returned buffer is written to C<*size_r>.
251 I<The caller must free the returned buffer after use>.\n\n"
253 if List.mem Progress flags then
254 pr "%s\n\n" progress_message;
255 if List.mem ProtocolLimitWarning flags then
256 pr "%s\n\n" protocol_limit_warning;
257 if List.exists (function Key _ -> true | _ -> false) (args@optargs) then
258 pr "This function takes a key or passphrase parameter which
259 could contain sensitive material. Read the section
260 L</KEYS AND PASSPHRASES> for more information.\n\n";
261 (match lookup_api_version name with
262 | Some version -> pr "(Added in %s)\n\n" version
266 (* Handling of optional argument variants. *)
267 if optargs <> [] then (
268 pr "=head2 %s_va\n\n" name;
269 generate_prototype ~extern:false ~indent:" " ~handle:"g"
270 ~prefix:"guestfs_" ~suffix:"_va" ~optarg_proto:VA
273 pr "This is the \"va_list variant\" of L</%s>.\n\n" name;
274 pr "See L</CALLS WITH OPTIONAL ARGUMENTS>.\n\n";
275 pr "=head2 %s_argv\n\n" name;
276 generate_prototype ~extern:false ~indent:" " ~handle:"g"
277 ~prefix:"guestfs_" ~suffix:"_argv" ~optarg_proto:Argv
280 pr "This is the \"argv variant\" of L</%s>.\n\n" name;
281 pr "See L</CALLS WITH OPTIONAL ARGUMENTS>.\n\n";
284 ) all_functions_sorted
286 and generate_structs_pod () =
287 (* Structs documentation. *)
290 pr "=head2 guestfs_%s\n" typ;
292 pr " struct guestfs_%s {\n" typ;
295 | name, FChar -> pr " char %s;\n" name
296 | name, FUInt32 -> pr " uint32_t %s;\n" name
297 | name, FInt32 -> pr " int32_t %s;\n" name
298 | name, (FUInt64|FBytes) -> pr " uint64_t %s;\n" name
299 | name, FInt64 -> pr " int64_t %s;\n" name
300 | name, FString -> pr " char *%s;\n" name
302 pr " /* The next two fields describe a byte array. */\n";
303 pr " uint32_t %s_len;\n" name;
304 pr " char *%s;\n" name
306 pr " /* The next field is NOT nul-terminated, be careful when printing it: */\n";
307 pr " char %s[32];\n" name
308 | name, FOptPercent ->
309 pr " /* The next field is [0..100] or -1 meaning 'not present': */\n";
310 pr " float %s;\n" name
314 pr " struct guestfs_%s_list {\n" typ;
315 pr " uint32_t len; /* Number of elements in list. */\n";
316 pr " struct guestfs_%s *val; /* Elements. */\n" typ;
319 pr " void guestfs_free_%s (struct guestfs_free_%s *);\n" typ typ;
320 pr " void guestfs_free_%s_list (struct guestfs_free_%s_list *);\n"
325 and generate_availability_pod () =
326 (* Availability documentation. *)
330 fun (group, functions) ->
331 pr "=item B<%s>\n" group;
333 pr "The following functions:\n";
334 List.iter (pr "L</guestfs_%s>\n") functions;
340 (* Generate the guestfs.h file. *)
341 and generate_guestfs_h () =
342 generate_header CStyle LGPLv2plus;
345 /* ---------- IMPORTANT NOTE ----------
347 * All API documentation is in the manpage, 'guestfs(3)'.
348 * To read it, type: man 3 guestfs
349 * Or read it online here: http://libguestfs.org/guestfs.3.html
351 * Go and read it now, I'll be right here waiting for you
352 * when you come back.
354 * ------------------------------------
369 # define GUESTFS_GCC_VERSION \\
370 (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
373 /* Define GUESTFS_WARN_DEPRECATED=1 to warn about deprecated API functions. */
374 #define GUESTFS_DEPRECATED_BY(s)
375 #if GUESTFS_WARN_DEPRECATED
376 # if defined(__GNUC__) && GUESTFS_GCC_VERSION >= 40500 /* gcc >= 4.5 */
377 # undef GUESTFS_DEPRECATED_BY
378 # define GUESTFS_DEPRECATED_BY(s) __attribute__((__deprecated__(\"change the program to use guestfs_\" s \" instead of this deprecated function\")))
380 #endif /* GUESTFS_WARN_DEPRECATED */
383 #ifndef GUESTFS_TYPEDEF_H
384 #define GUESTFS_TYPEDEF_H 1
385 typedef struct guestfs_h guestfs_h;
388 /* Connection management. */
389 extern guestfs_h *guestfs_create (void);
390 extern void guestfs_close (guestfs_h *g);
392 /* Error handling. */
393 extern const char *guestfs_last_error (guestfs_h *g);
394 #define LIBGUESTFS_HAVE_LAST_ERRNO 1
395 extern int guestfs_last_errno (guestfs_h *g);
397 #ifndef GUESTFS_TYPEDEF_ERROR_HANDLER_CB
398 #define GUESTFS_TYPEDEF_ERROR_HANDLER_CB 1
399 typedef void (*guestfs_error_handler_cb) (guestfs_h *g, void *opaque, const char *msg);
402 #ifndef GUESTFS_TYPEDEF_ABORT_CB
403 #define GUESTFS_TYPEDEF_ABORT_CB 1
404 typedef void (*guestfs_abort_cb) (void) __attribute__((__noreturn__));
407 extern void guestfs_set_error_handler (guestfs_h *g, guestfs_error_handler_cb cb, void *opaque);
408 extern guestfs_error_handler_cb guestfs_get_error_handler (guestfs_h *g, void **opaque_rtn);
410 extern void guestfs_set_out_of_memory_handler (guestfs_h *g, guestfs_abort_cb);
411 extern guestfs_abort_cb guestfs_get_out_of_memory_handler (guestfs_h *g);
417 fun (name, bitmask) ->
418 pr "#define GUESTFS_EVENT_%-16s 0x%04x\n"
419 (String.uppercase name) bitmask
421 pr "#define GUESTFS_EVENT_%-16s UINT64_MAX\n" "ALL";
425 #ifndef GUESTFS_TYPEDEF_EVENT_CALLBACK
426 #define GUESTFS_TYPEDEF_EVENT_CALLBACK 1
427 typedef void (*guestfs_event_callback) (
433 const char *buf, size_t buf_len,
434 const uint64_t *array, size_t array_len);
437 #define LIBGUESTFS_HAVE_SET_EVENT_CALLBACK 1
438 extern int guestfs_set_event_callback (guestfs_h *g,
439 guestfs_event_callback cb,
440 uint64_t event_bitmask,
443 #define LIBGUESTFS_HAVE_DELETE_EVENT_CALLBACK 1
444 extern void guestfs_delete_event_callback (guestfs_h *g, int event_handle);
446 /* Old-style event handling. */
447 #ifndef GUESTFS_TYPEDEF_LOG_MESSAGE_CB
448 #define GUESTFS_TYPEDEF_LOG_MESSAGE_CB 1
449 typedef void (*guestfs_log_message_cb) (guestfs_h *g, void *opaque, char *buf, int len);
452 #ifndef GUESTFS_TYPEDEF_SUBPROCESS_QUIT_CB
453 #define GUESTFS_TYPEDEF_SUBPROCESS_QUIT_CB 1
454 typedef void (*guestfs_subprocess_quit_cb) (guestfs_h *g, void *opaque);
457 #ifndef GUESTFS_TYPEDEF_LAUNCH_DONE_CB
458 #define GUESTFS_TYPEDEF_LAUNCH_DONE_CB 1
459 typedef void (*guestfs_launch_done_cb) (guestfs_h *g, void *opaque);
462 #ifndef GUESTFS_TYPEDEF_CLOSE_CB
463 #define GUESTFS_TYPEDEF_CLOSE_CB 1
464 typedef void (*guestfs_close_cb) (guestfs_h *g, void *opaque);
467 #ifndef GUESTFS_TYPEDEF_PROGRESS_CB
468 #define GUESTFS_TYPEDEF_PROGRESS_CB 1
469 typedef void (*guestfs_progress_cb) (guestfs_h *g, void *opaque, int proc_nr, int serial, uint64_t position, uint64_t total);
472 extern void guestfs_set_log_message_callback (guestfs_h *g, guestfs_log_message_cb cb, void *opaque)
473 GUESTFS_DEPRECATED_BY(\"set_event_callback\");
474 extern void guestfs_set_subprocess_quit_callback (guestfs_h *g, guestfs_subprocess_quit_cb cb, void *opaque)
475 GUESTFS_DEPRECATED_BY(\"set_event_callback\");
476 extern void guestfs_set_launch_done_callback (guestfs_h *g, guestfs_launch_done_cb cb, void *opaque)
477 GUESTFS_DEPRECATED_BY(\"set_event_callback\");
478 #define LIBGUESTFS_HAVE_SET_CLOSE_CALLBACK 1
479 extern void guestfs_set_close_callback (guestfs_h *g, guestfs_close_cb cb, void *opaque)
480 GUESTFS_DEPRECATED_BY(\"set_event_callback\");
481 #define LIBGUESTFS_HAVE_SET_PROGRESS_CALLBACK 1
482 extern void guestfs_set_progress_callback (guestfs_h *g, guestfs_progress_cb cb, void *opaque)
483 GUESTFS_DEPRECATED_BY(\"set_event_callback\");
485 /* User cancellation. */
486 #define LIBGUESTFS_HAVE_USER_CANCEL 1
487 extern void guestfs_user_cancel (guestfs_h *g);
489 /* Private data area. */
490 #define LIBGUESTFS_HAVE_SET_PRIVATE 1
491 extern void guestfs_set_private (guestfs_h *g, const char *key, void *data);
492 #define LIBGUESTFS_HAVE_GET_PRIVATE 1
493 extern void *guestfs_get_private (guestfs_h *g, const char *key);
494 #define LIBGUESTFS_HAVE_FIRST_PRIVATE 1
495 extern void *guestfs_first_private (guestfs_h *g, const char **key_rtn);
496 #define LIBGUESTFS_HAVE_NEXT_PRIVATE 1
497 extern void *guestfs_next_private (guestfs_h *g, const char **key_rtn);
502 (* The structures are carefully written to have exactly the same
503 * in-memory format as the XDR structures that we use on the wire to
504 * the daemon. The reason for creating copies of these structures
505 * here is just so we don't have to export the whole of
506 * guestfs_protocol.h (which includes much unrelated and
507 * XDR-dependent stuff that we don't want to be public, or required
510 * To reiterate, we will pass these structures to and from the client
511 * with a simple assignment or memcpy, so the format must be
512 * identical to what rpcgen / the RFC defines.
515 (* Public structures. *)
518 pr "struct guestfs_%s {\n" typ;
521 | name, FChar -> pr " char %s;\n" name
522 | name, FString -> pr " char *%s;\n" name
524 pr " uint32_t %s_len;\n" name;
525 pr " char *%s;\n" name
526 | name, FUUID -> pr " char %s[32]; /* this is NOT nul-terminated, be careful when printing */\n" name
527 | name, FUInt32 -> pr " uint32_t %s;\n" name
528 | name, FInt32 -> pr " int32_t %s;\n" name
529 | name, (FUInt64|FBytes) -> pr " uint64_t %s;\n" name
530 | name, FInt64 -> pr " int64_t %s;\n" name
531 | name, FOptPercent -> pr " float %s; /* [0..100] or -1 */\n" name
535 pr "struct guestfs_%s_list {\n" typ;
536 pr " uint32_t len;\n";
537 pr " struct guestfs_%s *val;\n" typ;
540 pr "extern void guestfs_free_%s (struct guestfs_%s *);\n" typ typ;
541 pr "extern void guestfs_free_%s_list (struct guestfs_%s_list *);\n" typ typ;
550 fun (shortname, (ret, args, optargs as style), _, flags, _, _, _) ->
553 Some (find_map (function DeprecatedBy fn -> Some fn | _ -> None)
555 with Not_found -> None in
557 String.length shortname >= 5 && String.sub shortname 0 5 = "test0" in
559 String.length shortname >= 5 && String.sub shortname 0 5 = "debug" in
560 if deprecated = None && not test0 && not debug then
561 pr "#define LIBGUESTFS_HAVE_%s 1\n" (String.uppercase shortname);
563 if optargs <> [] then (
566 let uc_shortname = String.uppercase shortname in
567 let n = name_of_argt argt in
568 let uc_n = String.uppercase n in
569 pr "#define GUESTFS_%s_%s %d\n" uc_shortname uc_n i;
573 generate_prototype ~single_line:true ~semicolon:false
574 ~handle:"g" ~prefix:"guestfs_" shortname style;
575 (match deprecated with
576 | Some fn -> pr "\n GUESTFS_DEPRECATED_BY (%S);\n" fn
580 if optargs <> [] then (
581 generate_prototype ~single_line:true ~newline:true ~handle:"g"
582 ~prefix:"guestfs_" ~suffix:"_va" ~optarg_proto:VA
586 pr "struct guestfs_%s_argv {\n" shortname;
587 pr " uint64_t bitmask;\n";
594 | Int64 n -> "int64_t "
595 | String n -> "const char *"
596 | _ -> assert false (* checked in generator_checks *) in
597 let uc_shortname = String.uppercase shortname in
598 let n = name_of_argt argt in
599 let uc_n = String.uppercase n in
601 pr "# define GUESTFS_%s_%s_BITMASK (UINT64_C(1)<<%d)\n" uc_shortname uc_n i;
602 pr " /* The field below is only valid in this struct if the\n";
603 pr " * GUESTFS_%s_%s_BITMASK bit is set\n" uc_shortname uc_n;
604 pr " * in the bitmask above. If not, the field is ignored.\n";
606 pr " %s%s;\n" c_type n
611 generate_prototype ~single_line:true ~newline:true ~handle:"g"
612 ~prefix:"guestfs_" ~suffix:"_argv" ~optarg_proto:Argv
617 ) all_functions_sorted;
621 /* Private functions.
623 * These are NOT part of the public, stable API, and can change at any
624 * time! We export them because they are used by some of the language
627 extern void *guestfs_safe_malloc (guestfs_h *g, size_t nbytes);
628 extern void *guestfs_safe_calloc (guestfs_h *g, size_t n, size_t s);
629 extern const char *guestfs_tmpdir (void);
630 #ifdef GUESTFS_PRIVATE_FOR_EACH_DISK
631 extern int guestfs___for_each_disk (guestfs_h *g, virDomainPtr dom, int (*)(guestfs_h *g, const char *filename, const char *format, int readonly, void *data), void *data);
633 /* End of private functions. */
639 #endif /* GUESTFS_H_ */
642 (* Generate the guestfs-internal-actions.h file. *)
643 and generate_internal_actions_h () =
644 generate_header CStyle LGPLv2plus;
646 fun (shortname, style, _, _, _, _, _) ->
647 generate_prototype ~single_line:true ~newline:true ~handle:"g"
648 ~prefix:"guestfs__" ~optarg_proto:Argv
650 ) non_daemon_functions
652 (* Generate the client-side dispatch stubs. *)
653 and generate_client_actions () =
654 generate_header CStyle LGPLv2plus;
661 #include <inttypes.h>
663 #include <sys/types.h>
664 #include <sys/stat.h>
667 #include \"guestfs.h\"
668 #include \"guestfs-internal.h\"
669 #include \"guestfs-internal-actions.h\"
670 #include \"guestfs_protocol.h\"
671 #include \"errnostring.h\"
673 /* Check the return message from a call for validity. */
675 check_reply_header (guestfs_h *g,
676 const struct guestfs_message_header *hdr,
677 unsigned int proc_nr, unsigned int serial)
679 if (hdr->prog != GUESTFS_PROGRAM) {
680 error (g, \"wrong program (%%d/%%d)\", hdr->prog, GUESTFS_PROGRAM);
683 if (hdr->vers != GUESTFS_PROTOCOL_VERSION) {
684 error (g, \"wrong protocol version (%%d/%%d)\",
685 hdr->vers, GUESTFS_PROTOCOL_VERSION);
688 if (hdr->direction != GUESTFS_DIRECTION_REPLY) {
689 error (g, \"unexpected message direction (%%d/%%d)\",
690 hdr->direction, GUESTFS_DIRECTION_REPLY);
693 if (hdr->proc != proc_nr) {
694 error (g, \"unexpected procedure number (%%d/%%d)\", hdr->proc, proc_nr);
697 if (hdr->serial != serial) {
698 error (g, \"unexpected serial (%%d/%%d)\", hdr->serial, serial);
705 /* Check we are in the right state to run a high-level action. */
707 check_state (guestfs_h *g, const char *caller)
709 if (!guestfs__is_ready (g)) {
710 if (guestfs__is_config (g) || guestfs__is_launching (g))
711 error (g, \"%%s: call launch before using this function\\n(in guestfish, don't forget to use the 'run' command)\",
714 error (g, \"%%s called from the wrong state, %%d != READY\",
715 caller, guestfs__get_state (g));
721 /* Convenience wrapper for tracing. */
723 trace_open (guestfs_h *g)
725 assert (g->trace_fp == NULL);
728 g->trace_fp = open_memstream (&g->trace_buf, &g->trace_len);
736 trace_send_line (guestfs_h *g)
742 fclose (g->trace_fp);
745 /* The callback might invoke other libguestfs calls, so keep
746 * a copy of the pointer to the buffer and length.
751 guestfs___call_callbacks_message (g, GUESTFS_EVENT_TRACE, buf, len);
759 (* Generate code for enter events. *)
760 let enter_event shortname =
761 pr " guestfs___call_callbacks_message (g, GUESTFS_EVENT_ENTER,\n";
763 shortname (String.length shortname)
766 (* Generate code to check String-like parameters are not passed in
767 * as NULL (returning an error if they are).
769 let check_null_strings shortname (ret, args, optargs) =
770 let pr_newline = ref false in
773 (* parameters which should not be NULL *)
785 pr " if (%s == NULL) {\n" n;
786 pr " error (g, \"%%s: %%s: parameter cannot be NULL\",\n";
787 pr " \"%s\", \"%s\");\n" shortname n;
789 match errcode_of_ret ret with
790 | `CannotReturnError ->
791 if shortname = "test0rconstoptstring" then (* XXX hack *)
795 "%s: RConstOptString function has invalid parameter '%s'"
797 | (`ErrorIsMinusOne |`ErrorIsNULL) as e -> e in
798 pr " return %s;\n" (string_of_errcode errcode);
811 (* For optional arguments. *)
815 pr " if ((optargs->bitmask & GUESTFS_%s_%s_BITMASK) &&\n"
816 (String.uppercase shortname) (String.uppercase n);
817 pr " optargs->%s == NULL) {\n" n;
818 pr " error (g, \"%%s: %%s: optional parameter cannot be NULL\",\n";
819 pr " \"%s\", \"%s\");\n" shortname n;
821 match errcode_of_ret ret with
822 | `CannotReturnError -> assert false
823 | (`ErrorIsMinusOne |`ErrorIsNULL) as e -> e in
824 pr " return %s;\n" (string_of_errcode errcode);
829 | Bool _ | Int _ | Int64 _ -> ()
834 if !pr_newline then pr "\n";
837 (* Generate code to reject optargs we don't know about. *)
838 let reject_unknown_optargs shortname = function
841 let len = List.length optargs in
842 let mask = Int64.lognot (Int64.pred (Int64.shift_left 1L len)) in
843 pr " if (optargs->bitmask & UINT64_C(0x%Lx)) {\n" mask;
844 pr " 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)\",\n";
845 pr " \"%s\", \"%s\");\n" shortname shortname;
847 match errcode_of_ret ret with
848 | `CannotReturnError -> assert false
849 | (`ErrorIsMinusOne |`ErrorIsNULL) as e -> e in
850 pr " return %s;\n" (string_of_errcode errcode);
855 (* Generate code to generate guestfish call traces. *)
856 let trace_call shortname (ret, args, optargs) =
857 pr " if (trace_flag) {\n";
860 List.exists (function
861 | StringList _ | DeviceList _ -> true
862 | _ -> false) args in
868 pr " trace_fp = trace_open (g);\n";
870 pr " fprintf (trace_fp, \"%%s\", \"%s\");\n" shortname;
872 (* Required arguments. *)
875 | String n (* strings *)
881 (* guestfish doesn't support string escaping, so neither do we *)
882 pr " fprintf (trace_fp, \" \\\"%%s\\\"\", %s);\n" n
884 (* don't print keys *)
885 pr " fprintf (trace_fp, \" \\\"***\\\"\");\n"
886 | OptString n -> (* string option *)
887 pr " if (%s) fprintf (trace_fp, \" \\\"%%s\\\"\", %s);\n" n n;
888 pr " else fprintf (trace_fp, \" null\");\n"
890 | DeviceList n -> (* string list *)
891 pr " fputc (' ', trace_fp);\n";
892 pr " fputc ('\"', trace_fp);\n";
893 pr " for (i = 0; %s[i]; ++i) {\n" n;
894 pr " if (i > 0) fputc (' ', trace_fp);\n";
895 pr " fputs (%s[i], trace_fp);\n" n;
897 pr " fputc ('\"', trace_fp);\n";
898 | Bool n -> (* boolean *)
899 pr " fputs (%s ? \" true\" : \" false\", trace_fp);\n" n
901 pr " fprintf (trace_fp, \" %%d\", %s);\n" n
903 pr " fprintf (trace_fp, \" %%\" PRIi64, %s);\n" n
904 | BufferIn n -> (* RHBZ#646822 *)
905 pr " fputc (' ', trace_fp);\n";
906 pr " guestfs___print_BufferIn (trace_fp, %s, %s_size);\n" n n
908 pr " fprintf (trace_fp, \" (%s)%%p\", %s);\n" t n
911 (* Optional arguments. *)
914 let n = name_of_argt argt in
915 let uc_shortname = String.uppercase shortname in
916 let uc_n = String.uppercase n in
917 pr " if (optargs->bitmask & GUESTFS_%s_%s_BITMASK)\n"
921 pr " fprintf (trace_fp, \" \\\"%%s:%%s\\\"\", \"%s\", optargs->%s);\n" n n
923 pr " fprintf (trace_fp, \" \\\"%%s:%%s\\\"\", \"%s\", optargs->%s ? \"true\" : \"false\");\n" n n
925 pr " fprintf (trace_fp, \" \\\"%%s:%%d\\\"\", \"%s\", optargs->%s);\n" n n
927 pr " fprintf (trace_fp, \" \\\"%%s:%%\" PRIi64 \"\\\"\", \"%s\", optargs->%s);\n" n n
932 pr " trace_send_line (g);\n";
937 let trace_return ?(indent = 2) shortname (ret, _, _) rv =
938 let indent = spaces indent in
940 pr "%sif (trace_flag) {\n" indent;
944 | RStringList _ | RHashtable _ -> true
947 pr "%s size_t i;\n" indent;
951 pr "%s trace_fp = trace_open (g);\n" indent;
953 pr "%s fprintf (trace_fp, \"%%s = \", \"%s\");\n" indent shortname;
956 | RErr | RInt _ | RBool _ ->
957 pr "%s fprintf (trace_fp, \"%%d\", %s);\n" indent rv
959 pr "%s fprintf (trace_fp, \"%%\" PRIi64, %s);\n" indent rv
960 | RConstString _ | RString _ ->
961 pr "%s fprintf (trace_fp, \"\\\"%%s\\\"\", %s);\n" indent rv
962 | RConstOptString _ ->
963 pr "%s fprintf (trace_fp, \"\\\"%%s\\\"\", %s != NULL ? %s : \"NULL\");\n"
966 pr "%s guestfs___print_BufferOut (trace_fp, %s, *size_r);\n" indent rv
967 | RStringList _ | RHashtable _ ->
968 pr "%s fputs (\"[\", trace_fp);\n" indent;
969 pr "%s for (i = 0; %s[i]; ++i) {\n" indent rv;
970 pr "%s if (i > 0) fputs (\", \", trace_fp);\n" indent;
971 pr "%s fputs (\"\\\"\", trace_fp);\n" indent;
972 pr "%s fputs (%s[i], trace_fp);\n" indent rv;
973 pr "%s fputs (\"\\\"\", trace_fp);\n" indent;
975 pr "%s fputs (\"]\", trace_fp);\n" indent;
976 | RStruct (_, typ) ->
977 (* XXX There is code generated for guestfish for printing
978 * these structures. We need to make it generally available
981 pr "%s fprintf (trace_fp, \"<struct guestfs_%s *>\");\n"
983 | RStructList (_, typ) ->
984 pr "%s fprintf (trace_fp, \"<struct guestfs_%s_list *>\");\n"
987 pr "%s trace_send_line (g);\n" indent;
992 let trace_return_error ?(indent = 2) shortname (ret, _, _) errcode =
993 let indent = spaces indent in
995 pr "%sif (trace_flag)\n" indent;
997 pr "%s guestfs___trace (g, \"%%s = %%s (error)\",\n" indent;
998 pr "%s \"%s\", \"%s\");\n"
999 indent shortname (string_of_errcode errcode)
1002 (* For non-daemon functions, generate a wrapper around each function. *)
1004 fun (shortname, (ret, _, optargs as style), _, _, _, _, _) ->
1005 if optargs = [] then
1006 generate_prototype ~extern:false ~semicolon:false ~newline:true
1007 ~handle:"g" ~prefix:"guestfs_"
1010 generate_prototype ~extern:false ~semicolon:false ~newline:true
1011 ~handle:"g" ~prefix:"guestfs_" ~suffix:"_argv" ~optarg_proto:Argv
1014 pr " int trace_flag = g->trace;\n";
1015 pr " FILE *trace_fp;\n";
1017 | RErr | RInt _ | RBool _ ->
1022 pr " const char *r;\n"
1023 | RConstOptString _ ->
1024 pr " const char *r;\n"
1025 | RString _ | RBufferOut _ ->
1027 | RStringList _ | RHashtable _ ->
1029 | RStruct (_, typ) ->
1030 pr " struct guestfs_%s *r;\n" typ
1031 | RStructList (_, typ) ->
1032 pr " struct guestfs_%s_list *r;\n" typ
1035 enter_event shortname;
1036 check_null_strings shortname style;
1037 reject_unknown_optargs shortname style;
1038 trace_call shortname style;
1039 pr " r = guestfs__%s " shortname;
1040 generate_c_call_args ~handle:"g" ~implicit_size_ptr:"size_r" style;
1043 (match errcode_of_ret ret with
1044 | (`ErrorIsMinusOne | `ErrorIsNULL) as errcode ->
1045 pr " if (r != %s) {\n" (string_of_errcode errcode);
1046 trace_return ~indent:4 shortname style "r";
1048 trace_return_error ~indent:4 shortname style errcode;
1050 | `CannotReturnError ->
1051 trace_return shortname style "r";
1057 ) non_daemon_functions;
1059 (* Client-side stubs for each function. *)
1061 fun (shortname, (ret, args, optargs as style), _, _, _, _, _) ->
1062 let name = "guestfs_" ^ shortname in
1064 match errcode_of_ret ret with
1065 | `CannotReturnError -> assert false
1066 | (`ErrorIsMinusOne | `ErrorIsNULL) as e -> e in
1068 (* Generate the action stub. *)
1069 if optargs = [] then
1070 generate_prototype ~extern:false ~semicolon:false ~newline:true
1071 ~handle:"g" ~prefix:"guestfs_" shortname style
1073 generate_prototype ~extern:false ~semicolon:false ~newline:true
1074 ~handle:"g" ~prefix:"guestfs_" ~suffix:"_argv"
1075 ~optarg_proto:Argv shortname style;
1081 | _ -> pr " struct %s_args args;\n" name
1084 pr " guestfs_message_header hdr;\n";
1085 pr " guestfs_message_error err;\n";
1089 | RConstString _ | RConstOptString _ ->
1090 failwithf "RConstString|RConstOptString cannot be used by daemon functions"
1092 | RBool _ | RString _ | RStringList _
1093 | RStruct _ | RStructList _
1094 | RHashtable _ | RBufferOut _ ->
1095 pr " struct %s_ret ret;\n" name;
1098 pr " int serial;\n";
1100 pr " int trace_flag = g->trace;\n";
1101 pr " FILE *trace_fp;\n";
1103 | RErr | RInt _ | RBool _ ->
1106 pr " int64_t ret_v;\n"
1107 | RConstString _ | RConstOptString _ ->
1108 pr " const char *ret_v;\n"
1109 | RString _ | RBufferOut _ ->
1110 pr " char *ret_v;\n"
1111 | RStringList _ | RHashtable _ ->
1112 pr " char **ret_v;\n"
1113 | RStruct (_, typ) ->
1114 pr " struct guestfs_%s *ret_v;\n" typ
1115 | RStructList (_, typ) ->
1116 pr " struct guestfs_%s_list *ret_v;\n" typ
1120 List.exists (function FileIn _ -> true | _ -> false) args in
1121 if has_filein then (
1122 pr " uint64_t progress_hint = 0;\n";
1123 pr " struct stat progress_stat;\n";
1125 pr " const uint64_t progress_hint = 0;\n";
1128 enter_event shortname;
1129 check_null_strings shortname style;
1130 reject_unknown_optargs shortname style;
1131 trace_call shortname style;
1133 (* Calculate the total size of all FileIn arguments to pass
1134 * as a progress bar hint.
1139 pr " if (stat (%s, &progress_stat) == 0 &&\n" n;
1140 pr " S_ISREG (progress_stat.st_mode))\n";
1141 pr " progress_hint += progress_stat.st_size;\n";
1146 (* Check we are in the right state for sending a request. *)
1147 pr " if (check_state (g, \"%s\") == -1) {\n" shortname;
1148 trace_return_error ~indent:4 shortname style errcode;
1149 pr " return %s;\n" (string_of_errcode errcode);
1151 pr " guestfs___set_busy (g);\n";
1154 (* Send the main header and arguments. *)
1155 if args = [] && optargs = [] then (
1156 pr " serial = guestfs___send (g, GUESTFS_PROC_%s, progress_hint, 0,\n"
1157 (String.uppercase shortname);
1158 pr " NULL, NULL);\n"
1162 | Pathname n | Device n | Dev_or_Path n | String n | Key n ->
1163 pr " args.%s = (char *) %s;\n" n n
1165 pr " args.%s = %s ? (char **) &%s : NULL;\n" n n n
1166 | StringList n | DeviceList n ->
1167 pr " args.%s.%s_val = (char **) %s;\n" n n n;
1168 pr " for (args.%s.%s_len = 0; %s[args.%s.%s_len]; args.%s.%s_len++) ;\n" n n n n n n n;
1170 pr " args.%s = %s;\n" n n
1172 pr " args.%s = %s;\n" n n
1174 pr " args.%s = %s;\n" n n
1175 | FileIn _ | FileOut _ -> ()
1177 pr " /* Just catch grossly large sizes. XDR encoding will make this precise. */\n";
1178 pr " if (%s_size >= GUESTFS_MESSAGE_MAX) {\n" n;
1179 trace_return_error ~indent:4 shortname style errcode;
1180 pr " error (g, \"%%s: size of input buffer too large\", \"%s\");\n"
1182 pr " guestfs___end_busy (g);\n";
1183 pr " return %s;\n" (string_of_errcode errcode);
1185 pr " args.%s.%s_val = (char *) %s;\n" n n n;
1186 pr " args.%s.%s_len = %s_size;\n" n n n
1187 | Pointer _ -> assert false
1192 let n = name_of_argt argt in
1193 let uc_shortname = String.uppercase shortname in
1194 let uc_n = String.uppercase n in
1195 pr " if ((optargs->bitmask & GUESTFS_%s_%s_BITMASK))\n"
1201 pr " args.%s = optargs->%s;\n" n n;
1203 pr " args.%s = 0;\n" n
1205 pr " args.%s = (char *) optargs->%s;\n" n n;
1207 pr " args.%s = (char *) \"\";\n" n
1212 pr " serial = guestfs___send (g, GUESTFS_PROC_%s,\n"
1213 (String.uppercase shortname);
1214 pr " progress_hint, %s,\n"
1215 (if optargs <> [] then "optargs->bitmask" else "0");
1216 pr " (xdrproc_t) xdr_%s_args, (char *) &args);\n"
1219 pr " if (serial == -1) {\n";
1220 pr " guestfs___end_busy (g);\n";
1221 trace_return_error ~indent:4 shortname style errcode;
1222 pr " return %s;\n" (string_of_errcode errcode);
1226 (* Send any additional files (FileIn) requested. *)
1227 let need_read_reply_label = ref false in
1231 pr " r = guestfs___send_file (g, %s);\n" n;
1232 pr " if (r == -1) {\n";
1233 pr " guestfs___end_busy (g);\n";
1234 trace_return_error ~indent:4 shortname style errcode;
1235 pr " /* daemon will send an error reply which we discard */\n";
1236 pr " guestfs___recv_discard (g, \"%s\");\n" shortname;
1237 pr " return %s;\n" (string_of_errcode errcode);
1239 pr " if (r == -2) /* daemon cancelled */\n";
1240 pr " goto read_reply;\n";
1241 need_read_reply_label := true;
1246 (* Wait for the reply from the remote end. *)
1247 if !need_read_reply_label then pr " read_reply:\n";
1248 pr " memset (&hdr, 0, sizeof hdr);\n";
1249 pr " memset (&err, 0, sizeof err);\n";
1250 if has_ret then pr " memset (&ret, 0, sizeof ret);\n";
1252 pr " r = guestfs___recv (g, \"%s\", &hdr, &err,\n " shortname;
1256 pr "(xdrproc_t) xdr_guestfs_%s_ret, (char *) &ret" shortname;
1259 pr " if (r == -1) {\n";
1260 pr " guestfs___end_busy (g);\n";
1261 trace_return_error ~indent:4 shortname style errcode;
1262 pr " return %s;\n" (string_of_errcode errcode);
1266 pr " if (check_reply_header (g, &hdr, GUESTFS_PROC_%s, serial) == -1) {\n"
1267 (String.uppercase shortname);
1268 pr " guestfs___end_busy (g);\n";
1269 trace_return_error ~indent:4 shortname style errcode;
1270 pr " return %s;\n" (string_of_errcode errcode);
1274 pr " if (hdr.status == GUESTFS_STATUS_ERROR) {\n";
1275 trace_return_error ~indent:4 shortname style errcode;
1276 pr " int errnum = 0;\n";
1277 pr " if (err.errno_string[0] != '\\0')\n";
1278 pr " errnum = guestfs___string_to_errno (err.errno_string);\n";
1279 pr " if (errnum <= 0)\n";
1280 pr " error (g, \"%%s: %%s\", \"%s\", err.error_message);\n"
1283 pr " guestfs_error_errno (g, errnum, \"%%s: %%s\", \"%s\",\n"
1285 pr " err.error_message);\n";
1286 pr " free (err.error_message);\n";
1287 pr " free (err.errno_string);\n";
1288 pr " guestfs___end_busy (g);\n";
1289 pr " return %s;\n" (string_of_errcode errcode);
1293 (* Expecting to receive further files (FileOut)? *)
1297 pr " if (guestfs___recv_file (g, %s) == -1) {\n" n;
1298 pr " guestfs___end_busy (g);\n";
1299 trace_return_error ~indent:4 shortname style errcode;
1300 pr " return %s;\n" (string_of_errcode errcode);
1306 pr " guestfs___end_busy (g);\n";
1311 | RInt n | RInt64 n | RBool n ->
1312 pr " ret_v = ret.%s;\n" n
1313 | RConstString _ | RConstOptString _ ->
1314 failwithf "RConstString|RConstOptString cannot be used by daemon functions"
1316 pr " ret_v = ret.%s; /* caller will free */\n" n
1317 | RStringList n | RHashtable n ->
1318 pr " /* caller will free this, but we need to add a NULL entry */\n";
1319 pr " ret.%s.%s_val =\n" n n;
1320 pr " safe_realloc (g, ret.%s.%s_val,\n" n n;
1321 pr " sizeof (char *) * (ret.%s.%s_len + 1));\n"
1323 pr " ret.%s.%s_val[ret.%s.%s_len] = NULL;\n" n n n n;
1324 pr " ret_v = ret.%s.%s_val;\n" n n
1326 pr " /* caller will free this */\n";
1327 pr " ret_v = safe_memdup (g, &ret.%s, sizeof (ret.%s));\n" n n
1328 | RStructList (n, _) ->
1329 pr " /* caller will free this */\n";
1330 pr " ret_v = safe_memdup (g, &ret.%s, sizeof (ret.%s));\n" n n
1332 pr " /* RBufferOut is tricky: If the buffer is zero-length, then\n";
1333 pr " * _val might be NULL here. To make the API saner for\n";
1334 pr " * callers, we turn this case into a unique pointer (using\n";
1335 pr " * malloc(1)).\n";
1337 pr " if (ret.%s.%s_len > 0) {\n" n n;
1338 pr " *size_r = ret.%s.%s_len;\n" n n;
1339 pr " ret_v = ret.%s.%s_val; /* caller will free */\n" n n;
1341 pr " free (ret.%s.%s_val);\n" n n;
1342 pr " char *p = safe_malloc (g, 1);\n";
1343 pr " *size_r = ret.%s.%s_len;\n" n n;
1347 trace_return shortname style "ret_v";
1348 pr " return ret_v;\n";
1352 (* Functions to free structures. *)
1353 pr "/* Structure-freeing functions. These rely on the fact that the\n";
1354 pr " * structure format is identical to the XDR format. See note in\n";
1355 pr " * generator.ml.\n";
1362 pr "guestfs_free_%s (struct guestfs_%s *x)\n" typ typ;
1364 pr " xdr_free ((xdrproc_t) xdr_guestfs_int_%s, (char *) x);\n" typ;
1370 pr "guestfs_free_%s_list (struct guestfs_%s_list *x)\n" typ typ;
1372 pr " xdr_free ((xdrproc_t) xdr_guestfs_int_%s_list, (char *) x);\n" typ;
1379 (* Functions which have optional arguments have two generated variants. *)
1382 | shortname, (ret, args, (_::_ as optargs) as style), _, _, _, _, _ ->
1383 let uc_shortname = String.uppercase shortname in
1385 (* Get the name of the last regular argument. *)
1388 | RBufferOut _ -> "size_r"
1392 | args -> name_of_argt (List.hd (List.rev args)) in
1396 | RErr | RInt _ | RBool _ -> "int "
1397 | RInt64 _ -> "int64_t "
1398 | RConstString _ | RConstOptString _ -> "const char *"
1399 | RString _ | RBufferOut _ -> "char *"
1400 | RStringList _ | RHashtable _ -> "char **"
1401 | RStruct (_, typ) -> sprintf "struct guestfs_%s *" typ
1402 | RStructList (_, typ) ->
1403 sprintf "struct guestfs_%s_list *" typ in
1405 (* The regular variable args function, just calls the _va variant. *)
1406 generate_prototype ~extern:false ~semicolon:false ~newline:true
1407 ~handle:"g" ~prefix:"guestfs_" shortname style;
1409 pr " va_list optargs;\n";
1411 pr " va_start (optargs, %s);\n" last_arg;
1412 pr " %sr = guestfs_%s_va " rtype shortname;
1413 generate_c_call_args ~handle:"g" ~implicit_size_ptr:"size_r" style;
1415 pr " va_end (optargs);\n";
1420 generate_prototype ~extern:false ~semicolon:false ~newline:true
1421 ~handle:"g" ~prefix:"guestfs_" ~suffix:"_va" ~optarg_proto:VA
1424 pr " struct guestfs_%s_argv optargs_s;\n" shortname;
1425 pr " struct guestfs_%s_argv *optargs = &optargs_s;\n" shortname;
1428 pr " optargs_s.bitmask = 0;\n";
1430 pr " while ((i = va_arg (args, int)) >= 0) {\n";
1431 pr " switch (i) {\n";
1435 let n = name_of_argt argt in
1436 let uc_n = String.uppercase n in
1437 pr " case GUESTFS_%s_%s:\n" uc_shortname uc_n;
1438 pr " optargs_s.%s = va_arg (args, " n;
1440 | Bool _ | Int _ -> pr "int"
1441 | Int64 _ -> pr "int64_t"
1442 | String _ -> pr "const char *"
1450 match errcode_of_ret ret with
1451 | `CannotReturnError -> assert false
1452 | (`ErrorIsMinusOne | `ErrorIsNULL) as e -> e in
1455 pr " 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)\",\n";
1456 pr " \"%s\", i);\n" shortname;
1457 pr " return %s;\n" (string_of_errcode errcode);
1460 pr " uint64_t i_mask = UINT64_C(1) << i;\n";
1461 pr " if (optargs_s.bitmask & i_mask) {\n";
1462 pr " error (g, \"%%s: same optional argument specified more than once\",\n";
1463 pr " \"%s\");\n" shortname;
1464 pr " return %s;\n" (string_of_errcode errcode);
1466 pr " optargs_s.bitmask |= i_mask;\n";
1469 pr " return guestfs_%s_argv " shortname;
1470 generate_c_call_args ~handle:"g" ~implicit_size_ptr:"size_r" style;
1474 ) all_functions_sorted
1476 (* Generate the linker script which controls the visibility of
1477 * symbols in the public ABI and ensures no other symbols get
1478 * exported accidentally.
1480 and generate_linker_script () =
1481 generate_header HashStyle GPLv2plus;
1486 "guestfs_delete_event_callback";
1487 "guestfs_first_private";
1488 "guestfs_get_error_handler";
1489 "guestfs_get_out_of_memory_handler";
1490 "guestfs_get_private";
1491 "guestfs_last_errno";
1492 "guestfs_last_error";
1493 "guestfs_next_private";
1494 "guestfs_set_close_callback";
1495 "guestfs_set_error_handler";
1496 "guestfs_set_event_callback";
1497 "guestfs_set_launch_done_callback";
1498 "guestfs_set_log_message_callback";
1499 "guestfs_set_out_of_memory_handler";
1500 "guestfs_set_private";
1501 "guestfs_set_progress_callback";
1502 "guestfs_set_subprocess_quit_callback";
1503 "guestfs_user_cancel";
1505 (* Unofficial parts of the API: the bindings code use these
1506 * functions, so it is useful to export them.
1508 "guestfs_safe_calloc";
1509 "guestfs_safe_malloc";
1510 "guestfs_safe_strdup";
1511 "guestfs_safe_memdup";
1513 "guestfs___for_each_disk";
1519 | name, (_, _, []), _, _, _, _, _ -> ["guestfs_" ^ name]
1520 | name, (_, _, _), _, _, _, _, _ ->
1522 "guestfs_" ^ name ^ "_va";
1523 "guestfs_" ^ name ^ "_argv"]
1528 List.map (fun (typ, _) ->
1529 ["guestfs_free_" ^ typ; "guestfs_free_" ^ typ ^ "_list"])
1532 let globals = List.sort compare (globals @ functions @ structs) in
1536 List.iter (pr " %s;\n") globals;
1543 and generate_max_proc_nr () =
1544 pr "%d\n" max_proc_nr