This command just writes a swap file signature to an existing
file. To create the file itself, use something like C<guestfs_fallocate>.");
+ ("inotify_init", (RErr, [Int "maxevents"]), 179, [],
+ [InitSquashFS, Always, TestRun (
+ [["inotify_init"; "0"]])],
+ "create an inotify handle",
+ "\
+This command creates a new inotify handle.
+The inotify subsystem can be used to notify events which happen to
+objects in the guest filesystem.
+
+C<maxevents> is the maximum number of events which will be
+queued up between calls to C<guestfs_inotify_read> or
+C<guestfs_inotify_files>.
+If this is passed as C<0>, then the kernel (or previously set)
+default is used. For Linux 2.6.29 the default was 16384 events.
+Beyond this limit, the kernel throws away events, but records
+the fact that it threw them away by setting a flag
+C<IN_Q_OVERFLOW> in the returned structure list (see
+C<guestfs_inotify_read>).
+
+Before any events are generated, you have to add some
+watches to the internal watch list. See:
+C<guestfs_inotify_add_watch>,
+C<guestfs_inotify_rm_watch> and
+C<guestfs_inotify_watch_all>.
+
+Queued up events should be read periodically by calling
+C<guestfs_inotify_read>
+(or C<guestfs_inotify_files> which is just a helpful
+wrapper around C<guestfs_inotify_read>). If you don't
+read the events out often enough then you risk the internal
+queue overflowing.
+
+The handle should be closed after use by calling
+C<guestfs_inotify_close>. This also removes any
+watches automatically.
+
+See also L<inotify(7)> for an overview of the inotify interface
+as exposed by the Linux kernel, which is roughly what we expose
+via libguestfs. Note that there is one global inotify handle
+per libguestfs instance.");
+
+ ("inotify_add_watch", (RInt64 "wd", [String "path"; Int "mask"]), 180, [],
+ [InitBasicFS, Always, TestOutputList (
+ [["inotify_init"; "0"];
+ ["inotify_add_watch"; "/"; "1073741823"];
+ ["touch"; "/a"];
+ ["touch"; "/b"];
+ ["inotify_files"]], ["a"; "b"])],
+ "add an inotify watch",
+ "\
+Watch C<path> for the events listed in C<mask>.
+
+Note that if C<path> is a directory then events within that
+directory are watched, but this does I<not> happen recursively
+(in subdirectories).
+
+Note for non-C or non-Linux callers: the inotify events are
+defined by the Linux kernel ABI and are listed in
+C</usr/include/sys/inotify.h>.");
+
+ ("inotify_rm_watch", (RErr, [Int(*XXX64*) "wd"]), 181, [],
+ [],
+ "remove an inotify watch",
+ "\
+Remove a previously defined inotify watch.
+See C<guestfs_inotify_add_watch>.");
+
+ ("inotify_read", (RStructList ("events", "inotify_event"), []), 182, [],
+ [],
+ "return list of inotify events",
+ "\
+Return the complete queue of events that have happened
+since the previous read call.
+
+If no events have happened, this returns an empty list.
+
+I<Note>: In order to make sure that all events have been
+read, you must call this function repeatedly until it
+returns an empty list. The reason is that the call will
+read events up to the maximum appliance-to-host message
+size and leave remaining events in the queue.");
+
+ ("inotify_files", (RStringList "paths", []), 183, [],
+ [],
+ "return list of watched files that had events",
+ "\
+This function is a helpful wrapper around C<guestfs_inotify_read>
+which just returns a list of pathnames of objects that were
+touched. The returned pathnames are sorted and deduplicated.");
+
+ ("inotify_close", (RErr, []), 184, [],
+ [],
+ "close the inotify handle",
+ "\
+This closes the inotify handle which was previously
+opened by inotify_init. It removes all watches, throws
+away any pending events, and deallocates all resources.");
+
]
let all_functions = non_daemon_functions @ daemon_functions
(* Field types for structures. *)
type field =
| FChar (* C 'char' (really, a 7 bit byte). *)
- | FString (* nul-terminated ASCII string. *)
+ | FString (* nul-terminated ASCII string, NOT NULL. *)
| FBuffer (* opaque buffer of bytes, (char *, int) pair *)
| FUInt32
| FInt32
"attrname", FString;
"attrval", FBuffer;
];
+
+ (* Inotify events. *)
+ "inotify_event", [
+ "in_wd", FInt64;
+ "in_mask", FUInt32;
+ "in_cookie", FUInt32;
+ "in_name", FString;
+ ];
] (* end of structs *)
(* Ugh, Java has to be different ..
"dirent", "Dirent";
"version", "Version";
"xattr", "XAttr";
+ "inotify_event", "INotifyEvent";
]
(* Used for testing language bindings. *)
| 1 -> false
| i -> failwithf "%s: failed with error code %d" cmd i
+let rec filter_map f = function
+ | [] -> []
+ | x :: xs ->
+ match f x with
+ | Some y -> y :: filter_map f xs
+ | None -> filter_map f xs
+
let rec find_map f = function
| [] -> raise Not_found
| x :: xs ->
}
*/
-static void no_test_warnings (void)
-{
";
+ (* Generate a list of commands which are not tested anywhere. *)
+ pr "static void no_test_warnings (void)\n";
+ pr "{\n";
+
+ let hash : (string, bool) Hashtbl.t = Hashtbl.create 13 in
List.iter (
- function
- | name, _, _, _, [], _, _ ->
+ fun (_, _, _, _, tests, _, _) ->
+ let tests = filter_map (
+ function
+ | (_, (Always|If _|Unless _), test) -> Some test
+ | (_, Disabled, _) -> None
+ ) tests in
+ let seq = List.concat (List.map seq_of_test tests) in
+ let cmds_tested = List.map List.hd seq in
+ List.iter (fun cmd -> Hashtbl.replace hash cmd true) cmds_tested
+ ) all_functions;
+
+ List.iter (
+ fun (name, _, _, _, _, _, _) ->
+ if not (Hashtbl.mem hash name) then
pr " fprintf (stderr, \"warning: \\\"guestfs_%s\\\" has no tests\\n\");\n" name
- | name, _, _, _, tests, _, _ -> ()
) all_functions;
pr "}\n";
let needs_i =
List.exists (function (_, (FUUID|FBuffer)) -> true | _ -> false) cols in
- pr "static void print_%s (struct guestfs_%s *%s)\n" typ typ typ;
+ pr "static void print_%s_indent (struct guestfs_%s *%s, const char *indent)\n" typ typ typ;
pr "{\n";
if needs_i then (
pr " int i;\n";
List.iter (
function
| name, FString ->
- pr " printf (\"%s: %%s\\n\", %s->%s);\n" name typ name
+ pr " printf (\"%%s%s: %%s\\n\", indent, %s->%s);\n" name typ name
| name, FUUID ->
pr " printf (\"%s: \");\n" name;
pr " for (i = 0; i < 32; ++i)\n";
- pr " printf (\"%%c\", %s->%s[i]);\n" typ name;
+ pr " printf (\"%%s%%c\", indent, %s->%s[i]);\n" typ name;
pr " printf (\"\\n\");\n"
| name, FBuffer ->
- pr " printf (\"%s: \");\n" name;
+ pr " printf (\"%%s%s: \", indent);\n" name;
pr " for (i = 0; i < %s->%s_len; ++i)\n" typ name;
pr " if (isprint (%s->%s[i]))\n" typ name;
- pr " printf (\"%%c\", %s->%s[i]);\n" typ name;
+ pr " printf (\"%%s%%c\", indent, %s->%s[i]);\n" typ name;
pr " else\n";
- pr " printf (\"\\\\x%%02x\", %s->%s[i]);\n" typ name;
+ pr " printf (\"%%s\\\\x%%02x\", indent, %s->%s[i]);\n" typ name;
pr " printf (\"\\n\");\n"
| name, (FUInt64|FBytes) ->
- pr " printf (\"%s: %%\" PRIu64 \"\\n\", %s->%s);\n" name typ name
+ pr " printf (\"%%s%s: %%\" PRIu64 \"\\n\", indent, %s->%s);\n"
+ name typ name
| name, FInt64 ->
- pr " printf (\"%s: %%\" PRIi64 \"\\n\", %s->%s);\n" name typ name
+ pr " printf (\"%%s%s: %%\" PRIi64 \"\\n\", indent, %s->%s);\n"
+ name typ name
| name, FUInt32 ->
- pr " printf (\"%s: %%\" PRIu32 \"\\n\", %s->%s);\n" name typ name
+ pr " printf (\"%%s%s: %%\" PRIu32 \"\\n\", indent, %s->%s);\n"
+ name typ name
| name, FInt32 ->
- pr " printf (\"%s: %%\" PRIi32 \"\\n\", %s->%s);\n" name typ name
+ pr " printf (\"%%s%s: %%\" PRIi32 \"\\n\", indent, %s->%s);\n"
+ name typ name
| name, FChar ->
- pr " printf (\"%s: %%c\\n\", %s->%s);\n" name typ name
+ pr " printf (\"%%s%s: %%c\\n\", indent, %s->%s);\n"
+ name typ name
| name, FOptPercent ->
- pr " if (%s->%s >= 0) printf (\"%s: %%g %%%%\\n\", %s->%s);\n"
+ pr " if (%s->%s >= 0) printf (\"%%s%s: %%g %%%%\\n\", indent, %s->%s);\n"
typ name name typ name;
- pr " else printf (\"%s: \\n\");\n" name
+ pr " else printf (\"%%s%s: \\n\", indent);\n" name
) cols;
pr "}\n";
pr "\n";
+ pr "static void print_%s (struct guestfs_%s *%s)\n" typ typ typ;
+ pr "{\n";
+ pr " print_%s_indent (%s, \"\");\n" typ typ;
+ pr "}\n";
+ pr "\n";
pr "static void print_%s_list (struct guestfs_%s_list *%ss)\n"
typ typ typ;
pr "{\n";
pr " int i;\n";
pr "\n";
- pr " for (i = 0; i < %ss->len; ++i)\n" typ;
- pr " print_%s (&%ss->val[i]);\n" typ typ;
+ pr " for (i = 0; i < %ss->len; ++i) {\n" typ;
+ pr " printf (\"[%%d] = {\\n\", i);\n";
+ pr " print_%s_indent (&%ss->val[i], \" \");\n" typ typ;
+ pr " printf (\"}\\n\");\n";
+ pr " }\n";
pr "}\n";
pr "\n";
) structs;