[Libguestfs] New API: node_nr_values

Kevin Haroldsen kupiakos at gmail.com
Mon Feb 15 21:19:58 UTC 2016


As a follow-up to node_nr_children discussed in
"hivex lib: Add function hivex_node_num_children",
I've also created the function node_nr_values, which just returns the
number of values of a node (primarily for optimization purposes).

I hope I've done it correctly so that a follow-up commit is unneeded.

The git tree is here: https://github.com/kupiakos/hivex/tree/node_nr_values
This is the patch:

diff --git a/generator/generator.ml b/generator/generator.ml
index 4f878ff..83fd276 100755
--- a/generator/generator.ml
+++ b/generator/generator.ml
@@ -242,6 +242,12 @@ string C<\"\"> here.  The default key is often
written C<\"@\">, but
 inside hives that has no meaning and won't give you the
 default key.";

+  "node_nr_values", (RSize, [AHive; ANode "node"]),
+    "return the number of values attached to a node",
+    "\
+Return the number of (key, value) pairs attached to this node
+as produced by C<hivex_node_values>.";
+
   "value_key_len", (RSize, [AHive; AValue "val"]),
     "return the length of a value's key",
     "\
diff --git a/lib/value.c b/lib/value.c
index 43e89f9..2dfe006 100644
--- a/lib/value.c
+++ b/lib/value.c
@@ -159,6 +159,22 @@ hivex_node_get_value (hive_h *h, hive_node_h
node, const char *key)
 }

 size_t
+hivex_node_nr_values (hive_h *h, hive_node_h node)
+{
+  if (!IS_VALID_BLOCK (h, node) || !block_id_eq (h, node, "nk")) {
+    SET_ERRNO (EINVAL, "invalid block or not an 'nk' block");
+    return 0;
+  }
+
+  struct ntreg_nk_record *nk =
+    (struct ntreg_nk_record *) ((char *) h->addr + node);
+
+  size_t nr_values = le32toh (nk->nr_values);
+
+  return nr_values;
+}
+
+size_t
 hivex_value_struct_length (hive_h *h, hive_value_h value)
 {
   size_t key_len;


Regards,
 - Kevin Haroldsen (kupiakos)




More information about the Libguestfs mailing list