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.mem DangerWillRobinson flags then
258 pr "%s\n\n" danger_will_robinson;
259 if List.exists (function Key _ -> true | _ -> false) (args@optargs) then
260 pr "This function takes a key or passphrase parameter which
261 could contain sensitive material. Read the section
262 L</KEYS AND PASSPHRASES> for more information.\n\n";
263 (match lookup_api_version name with
264 | Some version -> pr "(Added in %s)\n\n" version
268 (* Handling of optional argument variants. *)
269 if optargs <> [] then (
270 pr "=head2 %s_va\n\n" name;
271 generate_prototype ~extern:false ~indent:" " ~handle:"g"
272 ~prefix:"guestfs_" ~suffix:"_va" ~optarg_proto:VA
275 pr "This is the \"va_list variant\" of L</%s>.\n\n" name;
276 pr "See L</CALLS WITH OPTIONAL ARGUMENTS>.\n\n";
277 pr "=head2 %s_argv\n\n" name;
278 generate_prototype ~extern:false ~indent:" " ~handle:"g"
279 ~prefix:"guestfs_" ~suffix:"_argv" ~optarg_proto:Argv
282 pr "This is the \"argv variant\" of L</%s>.\n\n" name;
283 pr "See L</CALLS WITH OPTIONAL ARGUMENTS>.\n\n";
286 ) all_functions_sorted
288 and generate_structs_pod () =
289 (* Structs documentation. *)
292 pr "=head2 guestfs_%s\n" typ;
294 pr " struct guestfs_%s {\n" typ;
297 | name, FChar -> pr " char %s;\n" name
298 | name, FUInt32 -> pr " uint32_t %s;\n" name
299 | name, FInt32 -> pr " int32_t %s;\n" name
300 | name, (FUInt64|FBytes) -> pr " uint64_t %s;\n" name
301 | name, FInt64 -> pr " int64_t %s;\n" name
302 | name, FString -> pr " char *%s;\n" name
304 pr " /* The next two fields describe a byte array. */\n";
305 pr " uint32_t %s_len;\n" name;
306 pr " char *%s;\n" name
308 pr " /* The next field is NOT nul-terminated, be careful when printing it: */\n";
309 pr " char %s[32];\n" name
310 | name, FOptPercent ->
311 pr " /* The next field is [0..100] or -1 meaning 'not present': */\n";
312 pr " float %s;\n" name
316 pr " struct guestfs_%s_list {\n" typ;
317 pr " uint32_t len; /* Number of elements in list. */\n";
318 pr " struct guestfs_%s *val; /* Elements. */\n" typ;
321 pr " void guestfs_free_%s (struct guestfs_free_%s *);\n" typ typ;
322 pr " void guestfs_free_%s_list (struct guestfs_free_%s_list *);\n"
327 and generate_availability_pod () =
328 (* Availability documentation. *)
332 fun (group, functions) ->
333 pr "=item B<%s>\n" group;
335 pr "The following functions:\n";
336 List.iter (pr "L</guestfs_%s>\n") functions;
342 (* Generate the guestfs.h file. *)
343 and generate_guestfs_h () =
344 generate_header CStyle LGPLv2plus;
347 /* ---------- IMPORTANT NOTE ----------
349 * All API documentation is in the manpage, 'guestfs(3)'.
350 * To read it, type: man 3 guestfs
351 * Or read it online here: http://libguestfs.org/guestfs.3.html
353 * Go and read it now, I'll be right here waiting for you
354 * when you come back.
356 * ------------------------------------
371 # define GUESTFS_GCC_VERSION \\
372 (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
375 /* Define GUESTFS_WARN_DEPRECATED=1 to warn about deprecated API functions. */
376 #define GUESTFS_DEPRECATED_BY(s)
377 #if GUESTFS_WARN_DEPRECATED
378 # if defined(__GNUC__) && GUESTFS_GCC_VERSION >= 40500 /* gcc >= 4.5 */
379 # undef GUESTFS_DEPRECATED_BY
380 # define GUESTFS_DEPRECATED_BY(s) __attribute__((__deprecated__(\"change the program to use guestfs_\" s \" instead of this deprecated function\")))
382 #endif /* GUESTFS_WARN_DEPRECATED */
385 #ifndef GUESTFS_TYPEDEF_H
386 #define GUESTFS_TYPEDEF_H 1
387 typedef struct guestfs_h guestfs_h;
390 /* Connection management. */
391 extern guestfs_h *guestfs_create (void);
392 extern void guestfs_close (guestfs_h *g);
394 /* Error handling. */
395 extern const char *guestfs_last_error (guestfs_h *g);
396 #define LIBGUESTFS_HAVE_LAST_ERRNO 1
397 extern int guestfs_last_errno (guestfs_h *g);
399 #ifndef GUESTFS_TYPEDEF_ERROR_HANDLER_CB
400 #define GUESTFS_TYPEDEF_ERROR_HANDLER_CB 1
401 typedef void (*guestfs_error_handler_cb) (guestfs_h *g, void *opaque, const char *msg);
404 #ifndef GUESTFS_TYPEDEF_ABORT_CB
405 #define GUESTFS_TYPEDEF_ABORT_CB 1
406 typedef void (*guestfs_abort_cb) (void) __attribute__((__noreturn__));
409 extern void guestfs_set_error_handler (guestfs_h *g, guestfs_error_handler_cb cb, void *opaque);
410 extern guestfs_error_handler_cb guestfs_get_error_handler (guestfs_h *g, void **opaque_rtn);
412 extern void guestfs_set_out_of_memory_handler (guestfs_h *g, guestfs_abort_cb);
413 extern guestfs_abort_cb guestfs_get_out_of_memory_handler (guestfs_h *g);
419 fun (name, bitmask) ->
420 pr "#define GUESTFS_EVENT_%-16s 0x%04x\n"
421 (String.uppercase name) bitmask
423 pr "#define GUESTFS_EVENT_%-16s UINT64_MAX\n" "ALL";
427 #ifndef GUESTFS_TYPEDEF_EVENT_CALLBACK
428 #define GUESTFS_TYPEDEF_EVENT_CALLBACK 1
429 typedef void (*guestfs_event_callback) (
435 const char *buf, size_t buf_len,
436 const uint64_t *array, size_t array_len);
439 #define LIBGUESTFS_HAVE_SET_EVENT_CALLBACK 1
440 extern int guestfs_set_event_callback (guestfs_h *g,
441 guestfs_event_callback cb,
442 uint64_t event_bitmask,
445 #define LIBGUESTFS_HAVE_DELETE_EVENT_CALLBACK 1
446 extern void guestfs_delete_event_callback (guestfs_h *g, int event_handle);
448 /* Old-style event handling. */
449 #ifndef GUESTFS_TYPEDEF_LOG_MESSAGE_CB
450 #define GUESTFS_TYPEDEF_LOG_MESSAGE_CB 1
451 typedef void (*guestfs_log_message_cb) (guestfs_h *g, void *opaque, char *buf, int len);
454 #ifndef GUESTFS_TYPEDEF_SUBPROCESS_QUIT_CB
455 #define GUESTFS_TYPEDEF_SUBPROCESS_QUIT_CB 1
456 typedef void (*guestfs_subprocess_quit_cb) (guestfs_h *g, void *opaque);
459 #ifndef GUESTFS_TYPEDEF_LAUNCH_DONE_CB
460 #define GUESTFS_TYPEDEF_LAUNCH_DONE_CB 1
461 typedef void (*guestfs_launch_done_cb) (guestfs_h *g, void *opaque);
464 #ifndef GUESTFS_TYPEDEF_CLOSE_CB
465 #define GUESTFS_TYPEDEF_CLOSE_CB 1
466 typedef void (*guestfs_close_cb) (guestfs_h *g, void *opaque);
469 #ifndef GUESTFS_TYPEDEF_PROGRESS_CB
470 #define GUESTFS_TYPEDEF_PROGRESS_CB 1
471 typedef void (*guestfs_progress_cb) (guestfs_h *g, void *opaque, int proc_nr, int serial, uint64_t position, uint64_t total);
474 extern void guestfs_set_log_message_callback (guestfs_h *g, guestfs_log_message_cb cb, void *opaque)
475 GUESTFS_DEPRECATED_BY(\"set_event_callback\");
476 extern void guestfs_set_subprocess_quit_callback (guestfs_h *g, guestfs_subprocess_quit_cb cb, void *opaque)
477 GUESTFS_DEPRECATED_BY(\"set_event_callback\");
478 extern void guestfs_set_launch_done_callback (guestfs_h *g, guestfs_launch_done_cb cb, void *opaque)
479 GUESTFS_DEPRECATED_BY(\"set_event_callback\");
480 #define LIBGUESTFS_HAVE_SET_CLOSE_CALLBACK 1
481 extern void guestfs_set_close_callback (guestfs_h *g, guestfs_close_cb cb, void *opaque)
482 GUESTFS_DEPRECATED_BY(\"set_event_callback\");
483 #define LIBGUESTFS_HAVE_SET_PROGRESS_CALLBACK 1
484 extern void guestfs_set_progress_callback (guestfs_h *g, guestfs_progress_cb cb, void *opaque)
485 GUESTFS_DEPRECATED_BY(\"set_event_callback\");
487 /* User cancellation. */
488 #define LIBGUESTFS_HAVE_USER_CANCEL 1
489 extern void guestfs_user_cancel (guestfs_h *g);
491 /* Private data area. */
492 #define LIBGUESTFS_HAVE_SET_PRIVATE 1
493 extern void guestfs_set_private (guestfs_h *g, const char *key, void *data);
494 #define LIBGUESTFS_HAVE_GET_PRIVATE 1
495 extern void *guestfs_get_private (guestfs_h *g, const char *key);
496 #define LIBGUESTFS_HAVE_FIRST_PRIVATE 1
497 extern void *guestfs_first_private (guestfs_h *g, const char **key_rtn);
498 #define LIBGUESTFS_HAVE_NEXT_PRIVATE 1
499 extern void *guestfs_next_private (guestfs_h *g, const char **key_rtn);
504 (* The structures are carefully written to have exactly the same
505 * in-memory format as the XDR structures that we use on the wire to
506 * the daemon. The reason for creating copies of these structures
507 * here is just so we don't have to export the whole of
508 * guestfs_protocol.h (which includes much unrelated and
509 * XDR-dependent stuff that we don't want to be public, or required
512 * To reiterate, we will pass these structures to and from the client
513 * with a simple assignment or memcpy, so the format must be
514 * identical to what rpcgen / the RFC defines.
517 (* Public structures. *)
520 pr "struct guestfs_%s {\n" typ;
523 | name, FChar -> pr " char %s;\n" name
524 | name, FString -> pr " char *%s;\n" name
526 pr " uint32_t %s_len;\n" name;
527 pr " char *%s;\n" name
528 | name, FUUID -> pr " char %s[32]; /* this is NOT nul-terminated, be careful when printing */\n" name
529 | name, FUInt32 -> pr " uint32_t %s;\n" name
530 | name, FInt32 -> pr " int32_t %s;\n" name
531 | name, (FUInt64|FBytes) -> pr " uint64_t %s;\n" name
532 | name, FInt64 -> pr " int64_t %s;\n" name
533 | name, FOptPercent -> pr " float %s; /* [0..100] or -1 */\n" name
537 pr "struct guestfs_%s_list {\n" typ;
538 pr " uint32_t len;\n";
539 pr " struct guestfs_%s *val;\n" typ;
542 pr "extern void guestfs_free_%s (struct guestfs_%s *);\n" typ typ;
543 pr "extern void guestfs_free_%s_list (struct guestfs_%s_list *);\n" typ typ;
552 fun (shortname, (ret, args, optargs as style), _, flags, _, _, _) ->
555 Some (find_map (function DeprecatedBy fn -> Some fn | _ -> None)
557 with Not_found -> None in
559 String.length shortname >= 5 && String.sub shortname 0 5 = "test0" in
561 String.length shortname >= 5 && String.sub shortname 0 5 = "debug" in
562 if deprecated = None && not test0 && not debug then
563 pr "#define LIBGUESTFS_HAVE_%s 1\n" (String.uppercase shortname);
565 if optargs <> [] then (
568 let uc_shortname = String.uppercase shortname in
569 let n = name_of_argt argt in
570 let uc_n = String.uppercase n in
571 pr "#define GUESTFS_%s_%s %d\n" uc_shortname uc_n i;
575 generate_prototype ~single_line:true ~semicolon:false
576 ~handle:"g" ~prefix:"guestfs_" shortname style;
577 (match deprecated with
578 | Some fn -> pr "\n GUESTFS_DEPRECATED_BY (%S);\n" fn
582 if optargs <> [] then (
583 generate_prototype ~single_line:true ~newline:true ~handle:"g"
584 ~prefix:"guestfs_" ~suffix:"_va" ~optarg_proto:VA
588 pr "struct guestfs_%s_argv {\n" shortname;
589 pr " uint64_t bitmask;\n";
596 | Int64 n -> "int64_t "
597 | String n -> "const char *"
598 | _ -> assert false (* checked in generator_checks *) in
599 let uc_shortname = String.uppercase shortname in
600 let n = name_of_argt argt in
601 let uc_n = String.uppercase n in
603 pr "# define GUESTFS_%s_%s_BITMASK (UINT64_C(1)<<%d)\n" uc_shortname uc_n i;
604 pr " /* The field below is only valid in this struct if the\n";
605 pr " * GUESTFS_%s_%s_BITMASK bit is set\n" uc_shortname uc_n;
606 pr " * in the bitmask above. If not, the field is ignored.\n";
608 pr " %s%s;\n" c_type n
613 generate_prototype ~single_line:true ~newline:true ~handle:"g"
614 ~prefix:"guestfs_" ~suffix:"_argv" ~optarg_proto:Argv
619 ) all_functions_sorted;
623 /* Private functions.
625 * These are NOT part of the public, stable API, and can change at any
626 * time! We export them because they are used by some of the language
629 extern void *guestfs_safe_malloc (guestfs_h *g, size_t nbytes);
630 extern void *guestfs_safe_calloc (guestfs_h *g, size_t n, size_t s);
631 extern const char *guestfs_tmpdir (void);
632 #ifdef GUESTFS_PRIVATE_FOR_EACH_DISK
633 extern int guestfs___for_each_disk (guestfs_h *g, virDomainPtr dom, int (*)(guestfs_h *g, const char *filename, const char *format, void *data), void *data);
635 /* End of private functions. */
641 #endif /* GUESTFS_H_ */
644 (* Generate the guestfs-internal-actions.h file. *)
645 and generate_internal_actions_h () =
646 generate_header CStyle LGPLv2plus;
648 fun (shortname, style, _, _, _, _, _) ->
649 generate_prototype ~single_line:true ~newline:true ~handle:"g"
650 ~prefix:"guestfs__" ~optarg_proto:Argv
652 ) non_daemon_functions
654 (* Generate the client-side dispatch stubs. *)
655 and generate_client_actions () =
656 generate_header CStyle LGPLv2plus;
663 #include <inttypes.h>
665 #include <sys/types.h>
666 #include <sys/stat.h>
669 #include \"guestfs.h\"
670 #include \"guestfs-internal.h\"
671 #include \"guestfs-internal-actions.h\"
672 #include \"guestfs_protocol.h\"
673 #include \"errnostring.h\"
675 /* Check the return message from a call for validity. */
677 check_reply_header (guestfs_h *g,
678 const struct guestfs_message_header *hdr,
679 unsigned int proc_nr, unsigned int serial)
681 if (hdr->prog != GUESTFS_PROGRAM) {
682 error (g, \"wrong program (%%d/%%d)\", hdr->prog, GUESTFS_PROGRAM);
685 if (hdr->vers != GUESTFS_PROTOCOL_VERSION) {
686 error (g, \"wrong protocol version (%%d/%%d)\",
687 hdr->vers, GUESTFS_PROTOCOL_VERSION);
690 if (hdr->direction != GUESTFS_DIRECTION_REPLY) {
691 error (g, \"unexpected message direction (%%d/%%d)\",
692 hdr->direction, GUESTFS_DIRECTION_REPLY);
695 if (hdr->proc != proc_nr) {
696 error (g, \"unexpected procedure number (%%d/%%d)\", hdr->proc, proc_nr);
699 if (hdr->serial != serial) {
700 error (g, \"unexpected serial (%%d/%%d)\", hdr->serial, serial);
707 /* Check we are in the right state to run a high-level action. */
709 check_state (guestfs_h *g, const char *caller)
711 if (!guestfs__is_ready (g)) {
712 if (guestfs__is_config (g) || guestfs__is_launching (g))
713 error (g, \"%%s: call launch before using this function\\n(in guestfish, don't forget to use the 'run' command)\",
716 error (g, \"%%s called from the wrong state, %%d != READY\",
717 caller, guestfs__get_state (g));
723 /* Convenience wrapper for tracing. */
725 trace_open (guestfs_h *g)
727 assert (g->trace_fp == NULL);
730 g->trace_fp = open_memstream (&g->trace_buf, &g->trace_len);
738 trace_send_line (guestfs_h *g)
744 fclose (g->trace_fp);
747 /* The callback might invoke other libguestfs calls, so keep
748 * a copy of the pointer to the buffer and length.
753 guestfs___call_callbacks_message (g, GUESTFS_EVENT_TRACE, buf, len);
761 (* Generate code for enter events. *)
762 let enter_event shortname =
763 pr " guestfs___call_callbacks_message (g, GUESTFS_EVENT_ENTER,\n";
765 shortname (String.length shortname)
768 (* Generate code to check String-like parameters are not passed in
769 * as NULL (returning an error if they are).
771 let check_null_strings shortname (ret, args, optargs) =
772 let pr_newline = ref false in
775 (* parameters which should not be NULL *)
787 pr " if (%s == NULL) {\n" n;
788 pr " error (g, \"%%s: %%s: parameter cannot be NULL\",\n";
789 pr " \"%s\", \"%s\");\n" shortname n;
791 match errcode_of_ret ret with
792 | `CannotReturnError ->
793 if shortname = "test0rconstoptstring" then (* XXX hack *)
797 "%s: RConstOptString function has invalid parameter '%s'"
799 | (`ErrorIsMinusOne |`ErrorIsNULL) as e -> e in
800 pr " return %s;\n" (string_of_errcode errcode);
813 (* For optional arguments. *)
817 pr " if ((optargs->bitmask & GUESTFS_%s_%s_BITMASK) &&\n"
818 (String.uppercase shortname) (String.uppercase n);
819 pr " optargs->%s == NULL) {\n" n;
820 pr " error (g, \"%%s: %%s: optional parameter cannot be NULL\",\n";
821 pr " \"%s\", \"%s\");\n" shortname n;
823 match errcode_of_ret ret with
824 | `CannotReturnError -> assert false
825 | (`ErrorIsMinusOne |`ErrorIsNULL) as e -> e in
826 pr " return %s;\n" (string_of_errcode errcode);
831 | Bool _ | Int _ | Int64 _ -> ()
836 if !pr_newline then pr "\n";
839 (* Generate code to reject optargs we don't know about. *)
840 let reject_unknown_optargs shortname = function
843 let len = List.length optargs in
844 let mask = Int64.lognot (Int64.pred (Int64.shift_left 1L len)) in
845 pr " if (optargs->bitmask & UINT64_C(0x%Lx)) {\n" mask;
846 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";
847 pr " \"%s\", \"%s\");\n" shortname shortname;
849 match errcode_of_ret ret with
850 | `CannotReturnError -> assert false
851 | (`ErrorIsMinusOne |`ErrorIsNULL) as e -> e in
852 pr " return %s;\n" (string_of_errcode errcode);
857 (* Generate code to generate guestfish call traces. *)
858 let trace_call shortname (ret, args, optargs) =
859 pr " if (trace_flag) {\n";
862 List.exists (function
863 | StringList _ | DeviceList _ -> true
864 | _ -> false) args in
870 pr " trace_fp = trace_open (g);\n";
872 pr " fprintf (trace_fp, \"%%s\", \"%s\");\n" shortname;
874 (* Required arguments. *)
877 | String n (* strings *)
883 (* guestfish doesn't support string escaping, so neither do we *)
884 pr " fprintf (trace_fp, \" \\\"%%s\\\"\", %s);\n" n
886 (* don't print keys *)
887 pr " fprintf (trace_fp, \" \\\"***\\\"\");\n"
888 | OptString n -> (* string option *)
889 pr " if (%s) fprintf (trace_fp, \" \\\"%%s\\\"\", %s);\n" n n;
890 pr " else fprintf (trace_fp, \" null\");\n"
892 | DeviceList n -> (* string list *)
893 pr " fputc (' ', trace_fp);\n";
894 pr " fputc ('\"', trace_fp);\n";
895 pr " for (i = 0; %s[i]; ++i) {\n" n;
896 pr " if (i > 0) fputc (' ', trace_fp);\n";
897 pr " fputs (%s[i], trace_fp);\n" n;
899 pr " fputc ('\"', trace_fp);\n";
900 | Bool n -> (* boolean *)
901 pr " fputs (%s ? \" true\" : \" false\", trace_fp);\n" n
903 pr " fprintf (trace_fp, \" %%d\", %s);\n" n
905 pr " fprintf (trace_fp, \" %%\" PRIi64, %s);\n" n
906 | BufferIn n -> (* RHBZ#646822 *)
907 pr " fputc (' ', trace_fp);\n";
908 pr " guestfs___print_BufferIn (trace_fp, %s, %s_size);\n" n n
910 pr " fprintf (trace_fp, \" (%s)%%p\", %s);\n" t n
913 (* Optional arguments. *)
916 let n = name_of_argt argt in
917 let uc_shortname = String.uppercase shortname in
918 let uc_n = String.uppercase n in
919 pr " if (optargs->bitmask & GUESTFS_%s_%s_BITMASK)\n"
923 pr " fprintf (trace_fp, \" \\\"%%s:%%s\\\"\", \"%s\", optargs->%s);\n" n n
925 pr " fprintf (trace_fp, \" \\\"%%s:%%s\\\"\", \"%s\", optargs->%s ? \"true\" : \"false\");\n" n n
927 pr " fprintf (trace_fp, \" \\\"%%s:%%d\\\"\", \"%s\", optargs->%s);\n" n n
929 pr " fprintf (trace_fp, \" \\\"%%s:%%\" PRIi64 \"\\\"\", \"%s\", optargs->%s);\n" n n
934 pr " trace_send_line (g);\n";
939 let trace_return ?(indent = 2) shortname (ret, _, _) rv =
940 let indent = spaces indent in
942 pr "%sif (trace_flag) {\n" indent;
946 | RStringList _ | RHashtable _ -> true
949 pr "%s size_t i;\n" indent;
953 pr "%s trace_fp = trace_open (g);\n" indent;
955 pr "%s fprintf (trace_fp, \"%%s = \", \"%s\");\n" indent shortname;
958 | RErr | RInt _ | RBool _ ->
959 pr "%s fprintf (trace_fp, \"%%d\", %s);\n" indent rv
961 pr "%s fprintf (trace_fp, \"%%\" PRIi64, %s);\n" indent rv
962 | RConstString _ | RString _ ->
963 pr "%s fprintf (trace_fp, \"\\\"%%s\\\"\", %s);\n" indent rv
964 | RConstOptString _ ->
965 pr "%s fprintf (trace_fp, \"\\\"%%s\\\"\", %s != NULL ? %s : \"NULL\");\n"
968 pr "%s guestfs___print_BufferOut (trace_fp, %s, *size_r);\n" indent rv
969 | RStringList _ | RHashtable _ ->
970 pr "%s fputs (\"[\", trace_fp);\n" indent;
971 pr "%s for (i = 0; %s[i]; ++i) {\n" indent rv;
972 pr "%s if (i > 0) fputs (\", \", trace_fp);\n" indent;
973 pr "%s fputs (\"\\\"\", trace_fp);\n" indent;
974 pr "%s fputs (%s[i], trace_fp);\n" indent rv;
975 pr "%s fputs (\"\\\"\", trace_fp);\n" indent;
977 pr "%s fputs (\"]\", trace_fp);\n" indent;
978 | RStruct (_, typ) ->
979 (* XXX There is code generated for guestfish for printing
980 * these structures. We need to make it generally available
983 pr "%s fprintf (trace_fp, \"<struct guestfs_%s *>\");\n"
985 | RStructList (_, typ) ->
986 pr "%s fprintf (trace_fp, \"<struct guestfs_%s_list *>\");\n"
989 pr "%s trace_send_line (g);\n" indent;
994 let trace_return_error ?(indent = 2) shortname (ret, _, _) errcode =
995 let indent = spaces indent in
997 pr "%sif (trace_flag)\n" indent;
999 pr "%s guestfs___trace (g, \"%%s = %%s (error)\",\n" indent;
1000 pr "%s \"%s\", \"%s\");\n"
1001 indent shortname (string_of_errcode errcode)
1004 (* For non-daemon functions, generate a wrapper around each function. *)
1006 fun (shortname, (ret, _, optargs as style), _, _, _, _, _) ->
1007 if optargs = [] then
1008 generate_prototype ~extern:false ~semicolon:false ~newline:true
1009 ~handle:"g" ~prefix:"guestfs_"
1012 generate_prototype ~extern:false ~semicolon:false ~newline:true
1013 ~handle:"g" ~prefix:"guestfs_" ~suffix:"_argv" ~optarg_proto:Argv
1016 pr " int trace_flag = g->trace;\n";
1017 pr " FILE *trace_fp;\n";
1019 | RErr | RInt _ | RBool _ ->
1024 pr " const char *r;\n"
1025 | RConstOptString _ ->
1026 pr " const char *r;\n"
1027 | RString _ | RBufferOut _ ->
1029 | RStringList _ | RHashtable _ ->
1031 | RStruct (_, typ) ->
1032 pr " struct guestfs_%s *r;\n" typ
1033 | RStructList (_, typ) ->
1034 pr " struct guestfs_%s_list *r;\n" typ
1037 enter_event shortname;
1038 check_null_strings shortname style;
1039 reject_unknown_optargs shortname style;
1040 trace_call shortname style;
1041 pr " r = guestfs__%s " shortname;
1042 generate_c_call_args ~handle:"g" ~implicit_size_ptr:"size_r" style;
1045 (match errcode_of_ret ret with
1046 | (`ErrorIsMinusOne | `ErrorIsNULL) as errcode ->
1047 pr " if (r != %s) {\n" (string_of_errcode errcode);
1048 trace_return ~indent:4 shortname style "r";
1050 trace_return_error ~indent:4 shortname style errcode;
1052 | `CannotReturnError ->
1053 trace_return shortname style "r";
1059 ) non_daemon_functions;
1061 (* Client-side stubs for each function. *)
1063 fun (shortname, (ret, args, optargs as style), _, _, _, _, _) ->
1064 let name = "guestfs_" ^ shortname in
1066 match errcode_of_ret ret with
1067 | `CannotReturnError -> assert false
1068 | (`ErrorIsMinusOne | `ErrorIsNULL) as e -> e in
1070 (* Generate the action stub. *)
1071 if optargs = [] then
1072 generate_prototype ~extern:false ~semicolon:false ~newline:true
1073 ~handle:"g" ~prefix:"guestfs_" shortname style
1075 generate_prototype ~extern:false ~semicolon:false ~newline:true
1076 ~handle:"g" ~prefix:"guestfs_" ~suffix:"_argv"
1077 ~optarg_proto:Argv shortname style;
1083 | _ -> pr " struct %s_args args;\n" name
1086 pr " guestfs_message_header hdr;\n";
1087 pr " guestfs_message_error err;\n";
1091 | RConstString _ | RConstOptString _ ->
1092 failwithf "RConstString|RConstOptString cannot be used by daemon functions"
1094 | RBool _ | RString _ | RStringList _
1095 | RStruct _ | RStructList _
1096 | RHashtable _ | RBufferOut _ ->
1097 pr " struct %s_ret ret;\n" name;
1100 pr " int serial;\n";
1102 pr " int trace_flag = g->trace;\n";
1103 pr " FILE *trace_fp;\n";
1105 | RErr | RInt _ | RBool _ ->
1108 pr " int64_t ret_v;\n"
1109 | RConstString _ | RConstOptString _ ->
1110 pr " const char *ret_v;\n"
1111 | RString _ | RBufferOut _ ->
1112 pr " char *ret_v;\n"
1113 | RStringList _ | RHashtable _ ->
1114 pr " char **ret_v;\n"
1115 | RStruct (_, typ) ->
1116 pr " struct guestfs_%s *ret_v;\n" typ
1117 | RStructList (_, typ) ->
1118 pr " struct guestfs_%s_list *ret_v;\n" typ
1122 List.exists (function FileIn _ -> true | _ -> false) args in
1123 if has_filein then (
1124 pr " uint64_t progress_hint = 0;\n";
1125 pr " struct stat progress_stat;\n";
1127 pr " const uint64_t progress_hint = 0;\n";
1130 enter_event shortname;
1131 check_null_strings shortname style;
1132 reject_unknown_optargs shortname style;
1133 trace_call shortname style;
1135 (* Calculate the total size of all FileIn arguments to pass
1136 * as a progress bar hint.
1141 pr " if (stat (%s, &progress_stat) == 0 &&\n" n;
1142 pr " S_ISREG (progress_stat.st_mode))\n";
1143 pr " progress_hint += progress_stat.st_size;\n";
1148 (* Check we are in the right state for sending a request. *)
1149 pr " if (check_state (g, \"%s\") == -1) {\n" shortname;
1150 trace_return_error ~indent:4 shortname style errcode;
1151 pr " return %s;\n" (string_of_errcode errcode);
1153 pr " guestfs___set_busy (g);\n";
1156 (* Send the main header and arguments. *)
1157 if args = [] && optargs = [] then (
1158 pr " serial = guestfs___send (g, GUESTFS_PROC_%s, progress_hint, 0,\n"
1159 (String.uppercase shortname);
1160 pr " NULL, NULL);\n"
1164 | Pathname n | Device n | Dev_or_Path n | String n | Key n ->
1165 pr " args.%s = (char *) %s;\n" n n
1167 pr " args.%s = %s ? (char **) &%s : NULL;\n" n n n
1168 | StringList n | DeviceList n ->
1169 pr " args.%s.%s_val = (char **) %s;\n" n n n;
1170 pr " for (args.%s.%s_len = 0; %s[args.%s.%s_len]; args.%s.%s_len++) ;\n" n n n n n n n;
1172 pr " args.%s = %s;\n" n n
1174 pr " args.%s = %s;\n" n n
1176 pr " args.%s = %s;\n" n n
1177 | FileIn _ | FileOut _ -> ()
1179 pr " /* Just catch grossly large sizes. XDR encoding will make this precise. */\n";
1180 pr " if (%s_size >= GUESTFS_MESSAGE_MAX) {\n" n;
1181 trace_return_error ~indent:4 shortname style errcode;
1182 pr " error (g, \"%%s: size of input buffer too large\", \"%s\");\n"
1184 pr " guestfs___end_busy (g);\n";
1185 pr " return %s;\n" (string_of_errcode errcode);
1187 pr " args.%s.%s_val = (char *) %s;\n" n n n;
1188 pr " args.%s.%s_len = %s_size;\n" n n n
1189 | Pointer _ -> assert false
1194 let n = name_of_argt argt in
1195 let uc_shortname = String.uppercase shortname in
1196 let uc_n = String.uppercase n in
1197 pr " if ((optargs->bitmask & GUESTFS_%s_%s_BITMASK))\n"
1203 pr " args.%s = optargs->%s;\n" n n;
1205 pr " args.%s = 0;\n" n
1207 pr " args.%s = (char *) optargs->%s;\n" n n;
1209 pr " args.%s = (char *) \"\";\n" n
1214 pr " serial = guestfs___send (g, GUESTFS_PROC_%s,\n"
1215 (String.uppercase shortname);
1216 pr " progress_hint, %s,\n"
1217 (if optargs <> [] then "optargs->bitmask" else "0");
1218 pr " (xdrproc_t) xdr_%s_args, (char *) &args);\n"
1221 pr " if (serial == -1) {\n";
1222 pr " guestfs___end_busy (g);\n";
1223 trace_return_error ~indent:4 shortname style errcode;
1224 pr " return %s;\n" (string_of_errcode errcode);
1228 (* Send any additional files (FileIn) requested. *)
1229 let need_read_reply_label = ref false in
1233 pr " r = guestfs___send_file (g, %s);\n" n;
1234 pr " if (r == -1) {\n";
1235 pr " guestfs___end_busy (g);\n";
1236 trace_return_error ~indent:4 shortname style errcode;
1237 pr " /* daemon will send an error reply which we discard */\n";
1238 pr " guestfs___recv_discard (g, \"%s\");\n" shortname;
1239 pr " return %s;\n" (string_of_errcode errcode);
1241 pr " if (r == -2) /* daemon cancelled */\n";
1242 pr " goto read_reply;\n";
1243 need_read_reply_label := true;
1248 (* Wait for the reply from the remote end. *)
1249 if !need_read_reply_label then pr " read_reply:\n";
1250 pr " memset (&hdr, 0, sizeof hdr);\n";
1251 pr " memset (&err, 0, sizeof err);\n";
1252 if has_ret then pr " memset (&ret, 0, sizeof ret);\n";
1254 pr " r = guestfs___recv (g, \"%s\", &hdr, &err,\n " shortname;
1258 pr "(xdrproc_t) xdr_guestfs_%s_ret, (char *) &ret" shortname;
1261 pr " if (r == -1) {\n";
1262 pr " guestfs___end_busy (g);\n";
1263 trace_return_error ~indent:4 shortname style errcode;
1264 pr " return %s;\n" (string_of_errcode errcode);
1268 pr " if (check_reply_header (g, &hdr, GUESTFS_PROC_%s, serial) == -1) {\n"
1269 (String.uppercase shortname);
1270 pr " guestfs___end_busy (g);\n";
1271 trace_return_error ~indent:4 shortname style errcode;
1272 pr " return %s;\n" (string_of_errcode errcode);
1276 pr " if (hdr.status == GUESTFS_STATUS_ERROR) {\n";
1277 trace_return_error ~indent:4 shortname style errcode;
1278 pr " int errnum = 0;\n";
1279 pr " if (err.errno_string[0] != '\\0')\n";
1280 pr " errnum = guestfs___string_to_errno (err.errno_string);\n";
1281 pr " if (errnum <= 0)\n";
1282 pr " error (g, \"%%s: %%s\", \"%s\", err.error_message);\n"
1285 pr " guestfs_error_errno (g, errnum, \"%%s: %%s\", \"%s\",\n"
1287 pr " err.error_message);\n";
1288 pr " free (err.error_message);\n";
1289 pr " free (err.errno_string);\n";
1290 pr " guestfs___end_busy (g);\n";
1291 pr " return %s;\n" (string_of_errcode errcode);
1295 (* Expecting to receive further files (FileOut)? *)
1299 pr " if (guestfs___recv_file (g, %s) == -1) {\n" n;
1300 pr " guestfs___end_busy (g);\n";
1301 trace_return_error ~indent:4 shortname style errcode;
1302 pr " return %s;\n" (string_of_errcode errcode);
1308 pr " guestfs___end_busy (g);\n";
1313 | RInt n | RInt64 n | RBool n ->
1314 pr " ret_v = ret.%s;\n" n
1315 | RConstString _ | RConstOptString _ ->
1316 failwithf "RConstString|RConstOptString cannot be used by daemon functions"
1318 pr " ret_v = ret.%s; /* caller will free */\n" n
1319 | RStringList n | RHashtable n ->
1320 pr " /* caller will free this, but we need to add a NULL entry */\n";
1321 pr " ret.%s.%s_val =\n" n n;
1322 pr " safe_realloc (g, ret.%s.%s_val,\n" n n;
1323 pr " sizeof (char *) * (ret.%s.%s_len + 1));\n"
1325 pr " ret.%s.%s_val[ret.%s.%s_len] = NULL;\n" n n n n;
1326 pr " ret_v = ret.%s.%s_val;\n" n n
1328 pr " /* caller will free this */\n";
1329 pr " ret_v = safe_memdup (g, &ret.%s, sizeof (ret.%s));\n" n n
1330 | RStructList (n, _) ->
1331 pr " /* caller will free this */\n";
1332 pr " ret_v = safe_memdup (g, &ret.%s, sizeof (ret.%s));\n" n n
1334 pr " /* RBufferOut is tricky: If the buffer is zero-length, then\n";
1335 pr " * _val might be NULL here. To make the API saner for\n";
1336 pr " * callers, we turn this case into a unique pointer (using\n";
1337 pr " * malloc(1)).\n";
1339 pr " if (ret.%s.%s_len > 0) {\n" n n;
1340 pr " *size_r = ret.%s.%s_len;\n" n n;
1341 pr " ret_v = ret.%s.%s_val; /* caller will free */\n" n n;
1343 pr " free (ret.%s.%s_val);\n" n n;
1344 pr " char *p = safe_malloc (g, 1);\n";
1345 pr " *size_r = ret.%s.%s_len;\n" n n;
1349 trace_return shortname style "ret_v";
1350 pr " return ret_v;\n";
1354 (* Functions to free structures. *)
1355 pr "/* Structure-freeing functions. These rely on the fact that the\n";
1356 pr " * structure format is identical to the XDR format. See note in\n";
1357 pr " * generator.ml.\n";
1364 pr "guestfs_free_%s (struct guestfs_%s *x)\n" typ typ;
1366 pr " xdr_free ((xdrproc_t) xdr_guestfs_int_%s, (char *) x);\n" typ;
1372 pr "guestfs_free_%s_list (struct guestfs_%s_list *x)\n" typ typ;
1374 pr " xdr_free ((xdrproc_t) xdr_guestfs_int_%s_list, (char *) x);\n" typ;
1381 (* Functions which have optional arguments have two generated variants. *)
1384 | shortname, (ret, args, (_::_ as optargs) as style), _, _, _, _, _ ->
1385 let uc_shortname = String.uppercase shortname in
1387 (* Get the name of the last regular argument. *)
1390 | RBufferOut _ -> "size_r"
1394 | args -> name_of_argt (List.hd (List.rev args)) in
1398 | RErr | RInt _ | RBool _ -> "int "
1399 | RInt64 _ -> "int64_t "
1400 | RConstString _ | RConstOptString _ -> "const char *"
1401 | RString _ | RBufferOut _ -> "char *"
1402 | RStringList _ | RHashtable _ -> "char **"
1403 | RStruct (_, typ) -> sprintf "struct guestfs_%s *" typ
1404 | RStructList (_, typ) ->
1405 sprintf "struct guestfs_%s_list *" typ in
1407 (* The regular variable args function, just calls the _va variant. *)
1408 generate_prototype ~extern:false ~semicolon:false ~newline:true
1409 ~handle:"g" ~prefix:"guestfs_" shortname style;
1411 pr " va_list optargs;\n";
1413 pr " va_start (optargs, %s);\n" last_arg;
1414 pr " %sr = guestfs_%s_va " rtype shortname;
1415 generate_c_call_args ~handle:"g" ~implicit_size_ptr:"size_r" style;
1417 pr " va_end (optargs);\n";
1422 generate_prototype ~extern:false ~semicolon:false ~newline:true
1423 ~handle:"g" ~prefix:"guestfs_" ~suffix:"_va" ~optarg_proto:VA
1426 pr " struct guestfs_%s_argv optargs_s;\n" shortname;
1427 pr " struct guestfs_%s_argv *optargs = &optargs_s;\n" shortname;
1430 pr " optargs_s.bitmask = 0;\n";
1432 pr " while ((i = va_arg (args, int)) >= 0) {\n";
1433 pr " switch (i) {\n";
1437 let n = name_of_argt argt in
1438 let uc_n = String.uppercase n in
1439 pr " case GUESTFS_%s_%s:\n" uc_shortname uc_n;
1440 pr " optargs_s.%s = va_arg (args, " n;
1442 | Bool _ | Int _ -> pr "int"
1443 | Int64 _ -> pr "int64_t"
1444 | String _ -> pr "const char *"
1452 match errcode_of_ret ret with
1453 | `CannotReturnError -> assert false
1454 | (`ErrorIsMinusOne | `ErrorIsNULL) as e -> e in
1457 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";
1458 pr " \"%s\", i);\n" shortname;
1459 pr " return %s;\n" (string_of_errcode errcode);
1462 pr " uint64_t i_mask = UINT64_C(1) << i;\n";
1463 pr " if (optargs_s.bitmask & i_mask) {\n";
1464 pr " error (g, \"%%s: same optional argument specified more than once\",\n";
1465 pr " \"%s\");\n" shortname;
1466 pr " return %s;\n" (string_of_errcode errcode);
1468 pr " optargs_s.bitmask |= i_mask;\n";
1471 pr " return guestfs_%s_argv " shortname;
1472 generate_c_call_args ~handle:"g" ~implicit_size_ptr:"size_r" style;
1476 ) all_functions_sorted
1478 (* Generate the linker script which controls the visibility of
1479 * symbols in the public ABI and ensures no other symbols get
1480 * exported accidentally.
1482 and generate_linker_script () =
1483 generate_header HashStyle GPLv2plus;
1488 "guestfs_delete_event_callback";
1489 "guestfs_first_private";
1490 "guestfs_get_error_handler";
1491 "guestfs_get_out_of_memory_handler";
1492 "guestfs_get_private";
1493 "guestfs_last_errno";
1494 "guestfs_last_error";
1495 "guestfs_next_private";
1496 "guestfs_set_close_callback";
1497 "guestfs_set_error_handler";
1498 "guestfs_set_event_callback";
1499 "guestfs_set_launch_done_callback";
1500 "guestfs_set_log_message_callback";
1501 "guestfs_set_out_of_memory_handler";
1502 "guestfs_set_private";
1503 "guestfs_set_progress_callback";
1504 "guestfs_set_subprocess_quit_callback";
1505 "guestfs_user_cancel";
1507 (* Unofficial parts of the API: the bindings code use these
1508 * functions, so it is useful to export them.
1510 "guestfs_safe_calloc";
1511 "guestfs_safe_malloc";
1512 "guestfs_safe_strdup";
1513 "guestfs_safe_memdup";
1515 "guestfs___for_each_disk";
1521 | name, (_, _, []), _, _, _, _, _ -> ["guestfs_" ^ name]
1522 | name, (_, _, _), _, _, _, _, _ ->
1524 "guestfs_" ^ name ^ "_va";
1525 "guestfs_" ^ name ^ "_argv"]
1530 List.map (fun (typ, _) ->
1531 ["guestfs_free_" ^ typ; "guestfs_free_" ^ typ ^ "_list"])
1534 let globals = List.sort compare (globals @ functions @ structs) in
1538 List.iter (pr " %s;\n") globals;
1545 and generate_max_proc_nr () =
1546 pr "%d\n" max_proc_nr