[jhbuild/wip/rootowned: 2/2] Pile of random initial code and text for rootfs management
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [jhbuild/wip/rootowned: 2/2] Pile of random initial code and text for rootfs management
- Date: Fri, 7 Oct 2011 15:09:55 +0000 (UTC)
commit 8bd3aabd2e3325aec273af4702fa5e1653d4990c
Author: Colin Walters <walters verbum org>
Date: Fri Oct 7 11:08:54 2011 -0400
Pile of random initial code and text for rootfs management
Makefile.am | 2 +-
configure.ac | 14 +-
jhbuild/Makefile.am | 6 -
rootfs-manager/DESIGN | 85 ++++
rootfs-manager/Makefile.am | 16 +
rootfs-manager/gvdb/README | 7 +
rootfs-manager/gvdb/gvdb-builder.c | 516 +++++++++++++++++++++++
rootfs-manager/gvdb/gvdb-builder.h | 57 +++
rootfs-manager/gvdb/gvdb-format.h | 87 ++++
rootfs-manager/gvdb/gvdb-reader.c | 675 +++++++++++++++++++++++++++++++
rootfs-manager/gvdb/gvdb-reader.h | 80 ++++
rootfs-manager/gvdb/gvdb.doap | 32 ++
rootfs-manager/jhbuild-rootfs-manager.c | 151 +++++++
13 files changed, 1716 insertions(+), 12 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index a9d90a8..3d3e439 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,6 @@
AUTOMAKE_OPTIONS = foreign
-SUBDIRS = po scripts triggers jhbuild buildbot
+SUBDIRS = po scripts triggers jhbuild buildbot rootfs-manager
if DOC_INSTALLATION_ENABLED
SUBDIRS += doc
diff --git a/configure.ac b/configure.ac
index 39a097a..aaf58fc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,14 +23,17 @@ PKG_PROG_PKG_CONFIG
AC_ARG_ENABLE(
os-building,
- AS_HELP_STRING([--enable-os-building=@<:@no/yes@:>@], [If specified, provide support for root-owned builds]),
- [enable_os_building=$enableval],
- [enable_os_building=no])
+ AS_HELP_STRING([--enable-rootfs-manager=@<:@no/yes@:>@], [If specified, provide support for root-owned builds]),
+ [enable_rootfs_manager=$enableval],
+ [enable_rootfs_manager=no])
-if test x$enable_os_building = xyes; then
+LT_PREREQ([2.2.6])
+LT_INIT([disable-static])
+
+if test x$enable_rootfs_manager != xno; then
PKG_CHECK_MODULES(GIO_UNIX, [gio-unix-2.0])
fi
-AM_CONDITIONAL(OS_BUILDING, test x$enable_os_building=xyes)
+AM_CONDITIONAL(ROOTFS_MANAGER, test x$enable_rootfs_manager != xno)
# Documentation
AC_ARG_ENABLE(
@@ -60,6 +63,7 @@ AC_CONFIG_FILES([
jhbuild/utils/Makefile
jhbuild/versioncontrol/Makefile
buildbot/Makefile
+ rootfs-manager/Makefile
])
AC_OUTPUT([
examples/jhbuild.desktop
diff --git a/jhbuild/Makefile.am b/jhbuild/Makefile.am
index 7c327fe..c41e605 100644
--- a/jhbuild/Makefile.am
+++ b/jhbuild/Makefile.am
@@ -10,9 +10,3 @@ app_PYTHON = \
main.py \
moduleset.py \
monkeypatch.py
-
-libexec_PROGRAMS = jhbuild-install-helper
-
-jhbuild_install_helper_SOURCES = jhbuild-install-helper.c
-jhbuild_install_helper_CFLAGS = $(GIO_UNIX_CFLAGS)
-jhbuild_install_helper_LIBS = $(GIO_UNIX_LIBS)
diff --git a/rootfs-manager/DESIGN b/rootfs-manager/DESIGN
new file mode 100644
index 0000000..5d4041b
--- /dev/null
+++ b/rootfs-manager/DESIGN
@@ -0,0 +1,85 @@
+Jhbuild rootfs manager
+
+This is a system service that controls "root" images. A root image
+here is not the same as a root filesystem (necessarily). It is simply
+a set of software compiled into an alternative root.
+
+== Component ==
+
+What we're building is components. A component corresponds to exactly
+one git repository.
+
+== A Root ==
+
+A root is composed of a set of artifacts, which overlay into a
+filesystem tree. Roots are actually read-only bind-mounts on top of a
+real writable location, which isn't "public".
+
+/gnome/root-3.2-opt/{share,include,lib}
+/gnome/root-3.2-debug/{share,include,lib}
+
+Roots may need a git style database of sha1sums, in order to do
+efficient updates. Hmm...should we go full on git style objects/?
+
+== Artifact ==
+
+An artifact is a binary result of compiling a component (there may be
+multiple). Think of an artifact as like a Linux distribution
+"package", except there are no runtime dependencies, conflicts, or
+pre/post scripts. It's basically just a gzipped tarball.
+
+Example:
+
+gdk-pixbuf,o=master,r=3.2-opt,b=opt,v=2.24.0-10-g1d39095,.tar.gz
+
+This is an artifact from the gdk-pixbuf component. Here's a decoding of the key/value pairs:
+
+o: The origin of the build - there are just "master" and "local"
+r: The name of the root this artifact was compiled against
+b: The name of the build flavor (known values are "opt" and "debug")
+v: The output of "git describe".
+
+== Configuration Management ==
+
+Have you ever been a system administrator on a zypper/yum system, done
+an RPM update, which then drops .rpmnew files in your /etc/ that you
+have to go and hunt for with "find" or something, and said to
+yourself, "Wow, this system is awesome!!!" ? Right, that's what I
+thought.
+
+Configuration (and systems) management is a tricky problem, and I
+certainly don't have a magic bullet. However, one large conceptual
+improvement I think is defaulting to "rebase" versus "merge".
+
+This means that we won't permit direct modification of /etc - instead,
+you HAVE to write a script which accomplishes your goals. It's
+recommended to make this script revision controlled. We just execute
+/etc/gnomeos/config.d/* in alphabetical order, while the rootfs is
+still mounted read-write.
+
+Hmm, probably we need to define it to operate on a shadow tree, which
+we then diff?
+
+If the script fails, we can roll back the update, or drop to a shell
+if interactive.
+
+== Local modifications ==
+
+A key point of this whole endeavour is that we want developers to be
+able to do local builds. This is surprisingly something not well
+supported by the Debian/Fedora's tools at least.
+
+=== Updating a root with a new local artifact ===
+
+Since roots are read-only, we can safely "cp -al" them (a fast and
+efficient operation). Let's walk through this:
+
+Let's say we build a new local gdk-pixbuf.
+/gnome/root-3.2-opt/
+
+
+== Updating roots from master ==
+
+Depending on the frequency of update, we could simply compute
+"expected delta" files and apply those. We should probably look at
+the git protocol here.
diff --git a/rootfs-manager/Makefile.am b/rootfs-manager/Makefile.am
new file mode 100644
index 0000000..f81afb1
--- /dev/null
+++ b/rootfs-manager/Makefile.am
@@ -0,0 +1,16 @@
+
+libexec_PROGRAMS =
+
+if ROOTFS_MANAGER
+
+noinst_LTLIBRARIES = libgvdb.la
+
+libgvdb_la_SOURCES = gvdb/gvdb-builder.c gvdb/gvdb-builder.h \
+ gvdb/gvdb-format.h gvdb/gvdb-reader.h gvdb/gvdb-reader.c
+
+libexec_PROGRAMS += jhbuild-rootfs-manager
+jhbuild_rootfs_manager_SOURCES = jhbuild-rootfs-manager.c
+jhbuild_rootfs_manager_CFLAGS = $(GIO_UNIX_CFLAGS)
+jhbuild_rootfs_manager_LIBS = $(GIO_UNIX_LIBS)
+
+endif
diff --git a/rootfs-manager/gvdb/README b/rootfs-manager/gvdb/README
new file mode 100644
index 0000000..94e6c5d
--- /dev/null
+++ b/rootfs-manager/gvdb/README
@@ -0,0 +1,7 @@
+DO NOT MODIFY ANY FILE IN THIS DIRECTORY
+
+(except maybe the Makefile.am)
+
+This directory is the result of a git subtree merge with the 'gvdb'
+module on git.gnome.org. Please apply fixes to the 'gvdb' module and
+perform a git merge.
diff --git a/rootfs-manager/gvdb/gvdb-builder.c b/rootfs-manager/gvdb/gvdb-builder.c
new file mode 100644
index 0000000..91adec6
--- /dev/null
+++ b/rootfs-manager/gvdb/gvdb-builder.c
@@ -0,0 +1,516 @@
+/*
+ * Copyright  2010 Codethink Limited
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the licence, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Ryan Lortie <desrt desrt ca>
+ */
+
+#include "gvdb-builder.h"
+#include "gvdb-format.h"
+
+#include <glib.h>
+#include <fcntl.h>
+#if !defined(G_OS_WIN32) || !defined(_MSC_VER)
+#include <unistd.h>
+#endif
+#include <string.h>
+
+
+struct _GvdbItem
+{
+ gchar *key;
+ guint32 hash_value;
+ guint32_le assigned_index;
+ GvdbItem *parent;
+ GvdbItem *sibling;
+ GvdbItem *next;
+
+ /* one of:
+ * this:
+ */
+ GVariant *value;
+
+ /* this: */
+ GHashTable *table;
+
+ /* or this: */
+ GvdbItem *child;
+};
+
+static void
+gvdb_item_free (gpointer data)
+{
+ GvdbItem *item = data;
+
+ g_free (item->key);
+
+ if (item->value)
+ g_variant_unref (item->value);
+
+ if (item->table)
+ g_hash_table_unref (item->table);
+
+ g_slice_free (GvdbItem, item);
+}
+
+GHashTable *
+gvdb_hash_table_new (GHashTable *parent,
+ const gchar *name_in_parent)
+{
+ GHashTable *table;
+
+ table = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, gvdb_item_free);
+
+ if (parent)
+ {
+ GvdbItem *item;
+
+ item = gvdb_hash_table_insert (parent, name_in_parent);
+ gvdb_item_set_hash_table (item, table);
+ }
+
+ return table;
+}
+
+static guint32
+djb_hash (const gchar *key)
+{
+ guint32 hash_value = 5381;
+
+ while (*key)
+ hash_value = hash_value * 33 + *(signed char *)key++;
+
+ return hash_value;
+}
+
+GvdbItem *
+gvdb_hash_table_insert (GHashTable *table,
+ const gchar *key)
+{
+ GvdbItem *item;
+
+ item = g_slice_new0 (GvdbItem);
+ item->key = g_strdup (key);
+ item->hash_value = djb_hash (key);
+
+ g_hash_table_insert (table, g_strdup (key), item);
+
+ return item;
+}
+
+void
+gvdb_hash_table_insert_string (GHashTable *table,
+ const gchar *key,
+ const gchar *value)
+{
+ GvdbItem *item;
+
+ item = gvdb_hash_table_insert (table, key);
+ gvdb_item_set_value (item, g_variant_new_string (value));
+}
+
+void
+gvdb_item_set_value (GvdbItem *item,
+ GVariant *value)
+{
+ g_return_if_fail (!item->value && !item->table && !item->child);
+
+ item->value = g_variant_ref_sink (value);
+}
+
+void
+gvdb_item_set_hash_table (GvdbItem *item,
+ GHashTable *table)
+{
+ g_return_if_fail (!item->value && !item->table && !item->child);
+
+ item->table = g_hash_table_ref (table);
+}
+
+void
+gvdb_item_set_parent (GvdbItem *item,
+ GvdbItem *parent)
+{
+ GvdbItem **node;
+
+ g_return_if_fail (g_str_has_prefix (item->key, parent->key));
+ g_return_if_fail (!parent->value && !parent->table);
+ g_return_if_fail (!item->parent && !item->sibling);
+
+ for (node = &parent->child; *node; node = &(*node)->sibling)
+ if (strcmp ((*node)->key, item->key) > 0)
+ break;
+
+ item->parent = parent;
+ item->sibling = *node;
+ *node = item;
+}
+
+typedef struct
+{
+ GvdbItem **buckets;
+ gint n_buckets;
+} HashTable;
+
+static HashTable *
+hash_table_new (gint n_buckets)
+{
+ HashTable *table;
+
+ table = g_slice_new (HashTable);
+ table->buckets = g_new0 (GvdbItem *, n_buckets);
+ table->n_buckets = n_buckets;
+
+ return table;
+}
+
+static void
+hash_table_free (HashTable *table)
+{
+ g_free (table->buckets);
+
+ g_slice_free (HashTable, table);
+}
+
+static void
+hash_table_insert (gpointer key,
+ gpointer value,
+ gpointer data)
+{
+ guint32 hash_value, bucket;
+ HashTable *table = data;
+ GvdbItem *item = value;
+
+ hash_value = djb_hash (key);
+ bucket = hash_value % table->n_buckets;
+ item->next = table->buckets[bucket];
+ table->buckets[bucket] = item;
+}
+
+static guint32_le
+item_to_index (GvdbItem *item)
+{
+ if (item != NULL)
+ return item->assigned_index;
+
+ return guint32_to_le (-1u);
+}
+
+typedef struct
+{
+ GQueue *chunks;
+ guint64 offset;
+ gboolean byteswap;
+} FileBuilder;
+
+typedef struct
+{
+ gsize offset;
+ gsize size;
+ gpointer data;
+} FileChunk;
+
+static gpointer
+file_builder_allocate (FileBuilder *fb,
+ guint alignment,
+ gsize size,
+ struct gvdb_pointer *pointer)
+{
+ FileChunk *chunk;
+
+ if (size == 0)
+ return NULL;
+
+ fb->offset += (-fb->offset) & (alignment - 1);
+ chunk = g_slice_new (FileChunk);
+ chunk->offset = fb->offset;
+ chunk->size = size;
+ chunk->data = g_malloc (size);
+
+ pointer->start = guint32_to_le (fb->offset);
+ fb->offset += size;
+ pointer->end = guint32_to_le (fb->offset);
+
+ g_queue_push_tail (fb->chunks, chunk);
+
+ return chunk->data;
+}
+
+static void
+file_builder_add_value (FileBuilder *fb,
+ GVariant *value,
+ struct gvdb_pointer *pointer)
+{
+ GVariant *variant, *normal;
+ gpointer data;
+ gsize size;
+
+ if (fb->byteswap)
+ {
+ value = g_variant_byteswap (value);
+ variant = g_variant_new_variant (value);
+ g_variant_unref (value);
+ }
+ else
+ variant = g_variant_new_variant (value);
+
+ normal = g_variant_get_normal_form (variant);
+ g_variant_unref (variant);
+
+ size = g_variant_get_size (normal);
+ data = file_builder_allocate (fb, 8, size, pointer);
+ g_variant_store (normal, data);
+ g_variant_unref (normal);
+}
+
+static void
+file_builder_add_string (FileBuilder *fb,
+ const gchar *string,
+ guint32_le *start,
+ guint16_le *size)
+{
+ FileChunk *chunk;
+ gsize length;
+
+ length = strlen (string);
+
+ chunk = g_slice_new (FileChunk);
+ chunk->offset = fb->offset;
+ chunk->size = length;
+ chunk->data = g_malloc (length);
+ memcpy (chunk->data, string, length);
+
+ *start = guint32_to_le (fb->offset);
+ *size = guint16_to_le (length);
+ fb->offset += length;
+
+ g_queue_push_tail (fb->chunks, chunk);
+}
+
+static void
+file_builder_allocate_for_hash (FileBuilder *fb,
+ gsize n_buckets,
+ gsize n_items,
+ guint bloom_shift,
+ gsize n_bloom_words,
+ guint32_le **bloom_filter,
+ guint32_le **hash_buckets,
+ struct gvdb_hash_item **hash_items,
+ struct gvdb_pointer *pointer)
+{
+ guint32_le bloom_hdr, table_hdr;
+ guchar *data;
+ gsize size;
+
+ g_assert (n_bloom_words < (1u << 27));
+
+ bloom_hdr = guint32_to_le (bloom_shift << 27 | n_bloom_words);
+ table_hdr = guint32_to_le (n_buckets);
+
+ size = sizeof bloom_hdr + sizeof table_hdr +
+ n_bloom_words * sizeof (guint32_le) +
+ n_buckets * sizeof (guint32_le) +
+ n_items * sizeof (struct gvdb_hash_item);
+
+ data = file_builder_allocate (fb, 4, size, pointer);
+
+#define chunk(s) (size -= (s), data += (s), data - (s))
+ memcpy (chunk (sizeof bloom_hdr), &bloom_hdr, sizeof bloom_hdr);
+ memcpy (chunk (sizeof table_hdr), &table_hdr, sizeof table_hdr);
+ *bloom_filter = (guint32_le *) chunk (n_bloom_words * sizeof (guint32_le));
+ *hash_buckets = (guint32_le *) chunk (n_buckets * sizeof (guint32_le));
+ *hash_items = (struct gvdb_hash_item *) chunk (n_items *
+ sizeof (struct gvdb_hash_item));
+ g_assert (size == 0);
+#undef chunk
+
+ memset (*bloom_filter, 0, n_bloom_words * sizeof (guint32_le));
+}
+
+static void
+file_builder_add_hash (FileBuilder *fb,
+ GHashTable *table,
+ struct gvdb_pointer *pointer)
+{
+ guint32_le *buckets, *bloom_filter;
+ struct gvdb_hash_item *items;
+ HashTable *mytable;
+ GvdbItem *item;
+ guint32 index;
+ gint bucket;
+
+ mytable = hash_table_new (g_hash_table_size (table));
+ g_hash_table_foreach (table, hash_table_insert, mytable);
+ index = 0;
+
+ for (bucket = 0; bucket < mytable->n_buckets; bucket++)
+ for (item = mytable->buckets[bucket]; item; item = item->next)
+ item->assigned_index = guint32_to_le (index++);
+
+ file_builder_allocate_for_hash (fb, mytable->n_buckets, index, 5, 0,
+ &bloom_filter, &buckets, &items, pointer);
+
+ index = 0;
+ for (bucket = 0; bucket < mytable->n_buckets; bucket++)
+ {
+ buckets[bucket] = guint32_to_le (index);
+
+ for (item = mytable->buckets[bucket]; item; item = item->next)
+ {
+ struct gvdb_hash_item *entry = items++;
+ const gchar *basename;
+
+ g_assert (index == guint32_from_le (item->assigned_index));
+ entry->hash_value = guint32_to_le (item->hash_value);
+ entry->parent = item_to_index (item->parent);
+ entry->unused = 0;
+
+ if (item->parent != NULL)
+ basename = item->key + strlen (item->parent->key);
+ else
+ basename = item->key;
+
+ file_builder_add_string (fb, basename,
+ &entry->key_start,
+ &entry->key_size);
+
+ if (item->value != NULL)
+ {
+ g_assert (item->child == NULL && item->table == NULL);
+
+ file_builder_add_value (fb, item->value, &entry->value.pointer);
+ entry->type = 'v';
+ }
+
+ if (item->child != NULL)
+ {
+ guint32 children = 0, i = 0;
+ guint32_le *offsets;
+ GvdbItem *child;
+
+ g_assert (item->table == NULL);
+
+ for (child = item->child; child; child = child->sibling)
+ children++;
+
+ offsets = file_builder_allocate (fb, 4, 4 * children,
+ &entry->value.pointer);
+ entry->type = 'L';
+
+ for (child = item->child; child; child = child->sibling)
+ offsets[i++] = child->assigned_index;
+
+ g_assert (children == i);
+ }
+
+ if (item->table != NULL)
+ {
+ entry->type = 'H';
+ file_builder_add_hash (fb, item->table, &entry->value.pointer);
+ }
+
+ index++;
+ }
+ }
+
+ hash_table_free (mytable);
+}
+
+static FileBuilder *
+file_builder_new (gboolean byteswap)
+{
+ FileBuilder *builder;
+
+ builder = g_slice_new (FileBuilder);
+ builder->chunks = g_queue_new ();
+ builder->offset = sizeof (struct gvdb_header);
+ builder->byteswap = byteswap;
+
+ return builder;
+}
+
+static GString *
+file_builder_serialise (FileBuilder *fb,
+ struct gvdb_pointer root)
+{
+ struct gvdb_header header = { { 0, }, };
+ GString *result;
+
+ if (fb->byteswap)
+ {
+ header.signature[0] = GVDB_SWAPPED_SIGNATURE0;
+ header.signature[1] = GVDB_SWAPPED_SIGNATURE1;
+ }
+ else
+ {
+ header.signature[0] = GVDB_SIGNATURE0;
+ header.signature[1] = GVDB_SIGNATURE1;
+ }
+
+ result = g_string_new (NULL);
+
+ header.root = root;
+ g_string_append_len (result, (gpointer) &header, sizeof header);
+
+ while (!g_queue_is_empty (fb->chunks))
+ {
+ FileChunk *chunk = g_queue_pop_head (fb->chunks);
+
+ if (result->len != chunk->offset)
+ {
+ gchar zero[8] = { 0, };
+
+ g_assert (chunk->offset > result->len);
+ g_assert (chunk->offset - result->len < 8);
+
+ g_string_append_len (result, zero, chunk->offset - result->len);
+ g_assert (result->len == chunk->offset);
+ }
+
+ g_string_append_len (result, chunk->data, chunk->size);
+ g_free (chunk->data);
+
+ g_slice_free (FileChunk, chunk);
+ }
+
+ g_queue_free (fb->chunks);
+ g_slice_free (FileBuilder, fb);
+
+ return result;
+}
+
+gboolean
+gvdb_table_write_contents (GHashTable *table,
+ const gchar *filename,
+ gboolean byteswap,
+ GError **error)
+{
+ struct gvdb_pointer root;
+ gboolean status;
+ FileBuilder *fb;
+ GString *str;
+
+ fb = file_builder_new (byteswap);
+ file_builder_add_hash (fb, table, &root);
+ str = file_builder_serialise (fb, root);
+
+ status = g_file_set_contents (filename, str->str, str->len, error);
+ g_string_free (str, TRUE);
+
+ return status;
+}
diff --git a/rootfs-manager/gvdb/gvdb-builder.h b/rootfs-manager/gvdb/gvdb-builder.h
new file mode 100644
index 0000000..797626e
--- /dev/null
+++ b/rootfs-manager/gvdb/gvdb-builder.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright  2010 Codethink Limited
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the licence, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Ryan Lortie <desrt desrt ca>
+ */
+
+#ifndef __gvdb_builder_h__
+#define __gvdb_builder_h__
+
+#include <gio/gio.h>
+
+typedef struct _GvdbItem GvdbItem;
+
+G_GNUC_INTERNAL
+GHashTable * gvdb_hash_table_new (GHashTable *parent,
+ const gchar *key);
+
+G_GNUC_INTERNAL
+GvdbItem * gvdb_hash_table_insert (GHashTable *table,
+ const gchar *key);
+G_GNUC_INTERNAL
+void gvdb_hash_table_insert_string (GHashTable *table,
+ const gchar *key,
+ const gchar *value);
+
+G_GNUC_INTERNAL
+void gvdb_item_set_value (GvdbItem *item,
+ GVariant *value);
+G_GNUC_INTERNAL
+void gvdb_item_set_hash_table (GvdbItem *item,
+ GHashTable *table);
+G_GNUC_INTERNAL
+void gvdb_item_set_parent (GvdbItem *item,
+ GvdbItem *parent);
+
+G_GNUC_INTERNAL
+gboolean gvdb_table_write_contents (GHashTable *table,
+ const gchar *filename,
+ gboolean byteswap,
+ GError **error);
+
+#endif /* __gvdb_builder_h__ */
diff --git a/rootfs-manager/gvdb/gvdb-format.h b/rootfs-manager/gvdb/gvdb-format.h
new file mode 100644
index 0000000..886aa56
--- /dev/null
+++ b/rootfs-manager/gvdb/gvdb-format.h
@@ -0,0 +1,87 @@
+/*
+ * Copyright  2010 Codethink Limited
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the licence, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Ryan Lortie <desrt desrt ca>
+ */
+
+#ifndef __gvdb_format_h__
+#define __gvdb_format_h__
+
+#include <glib.h>
+
+typedef struct { guint16 value; } guint16_le;
+typedef struct { guint32 value; } guint32_le;
+
+struct gvdb_pointer {
+ guint32_le start;
+ guint32_le end;
+};
+
+struct gvdb_hash_header {
+ guint32_le n_bloom_words;
+ guint32_le n_buckets;
+};
+
+struct gvdb_hash_item {
+ guint32_le hash_value;
+ guint32_le parent;
+
+ guint32_le key_start;
+ guint16_le key_size;
+ gchar type;
+ gchar unused;
+
+ union
+ {
+ struct gvdb_pointer pointer;
+ gchar direct[8];
+ } value;
+};
+
+struct gvdb_header {
+ guint32 signature[2];
+ guint32_le version;
+ guint32_le options;
+
+ struct gvdb_pointer root;
+};
+
+static inline guint32_le guint32_to_le (guint32 value) {
+ guint32_le result = { GUINT32_TO_LE (value) };
+ return result;
+}
+
+static inline guint32 guint32_from_le (guint32_le value) {
+ return GUINT32_FROM_LE (value.value);
+}
+
+static inline guint16_le guint16_to_le (guint16 value) {
+ guint16_le result = { GUINT16_TO_LE (value) };
+ return result;
+}
+
+static inline guint16 guint16_from_le (guint16_le value) {
+ return GUINT16_FROM_LE (value.value);
+}
+
+#define GVDB_SIGNATURE0 1918981703
+#define GVDB_SIGNATURE1 1953390953
+#define GVDB_SWAPPED_SIGNATURE0 GUINT32_SWAP_LE_BE (GVDB_SIGNATURE0)
+#define GVDB_SWAPPED_SIGNATURE1 GUINT32_SWAP_LE_BE (GVDB_SIGNATURE1)
+
+#endif /* __gvdb_format_h__ */
diff --git a/rootfs-manager/gvdb/gvdb-reader.c b/rootfs-manager/gvdb/gvdb-reader.c
new file mode 100644
index 0000000..57816af
--- /dev/null
+++ b/rootfs-manager/gvdb/gvdb-reader.c
@@ -0,0 +1,675 @@
+/*
+ * Copyright  2010 Codethink Limited
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the licence, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Ryan Lortie <desrt desrt ca>
+ */
+
+#include "gvdb-reader.h"
+#include "gvdb-format.h"
+
+#include <string.h>
+
+struct _GvdbTable {
+ gint ref_count;
+
+ const gchar *data;
+ gsize size;
+
+ GMappedFile *mapped;
+ gboolean byteswapped;
+ gboolean trusted;
+
+ const guint32_le *bloom_words;
+ guint32 n_bloom_words;
+ guint bloom_shift;
+
+ const guint32_le *hash_buckets;
+ guint32 n_buckets;
+
+ struct gvdb_hash_item *hash_items;
+ guint32 n_hash_items;
+};
+
+static const gchar *
+gvdb_table_item_get_key (GvdbTable *file,
+ const struct gvdb_hash_item *item,
+ gsize *size)
+{
+ guint32 start, end;
+
+ start = guint32_from_le (item->key_start);
+ *size = guint16_from_le (item->key_size);
+ end = start + *size;
+
+ if G_UNLIKELY (start > end || end > file->size)
+ return NULL;
+
+ return file->data + start;
+}
+
+static gconstpointer
+gvdb_table_dereference (GvdbTable *file,
+ const struct gvdb_pointer *pointer,
+ gint alignment,
+ gsize *size)
+{
+ guint32 start, end;
+
+ start = guint32_from_le (pointer->start);
+ end = guint32_from_le (pointer->end);
+
+ if G_UNLIKELY (start > end || end > file->size || start & (alignment - 1))
+ return NULL;
+
+ *size = end - start;
+
+ return file->data + start;
+}
+
+static void
+gvdb_table_setup_root (GvdbTable *file,
+ const struct gvdb_pointer *pointer)
+{
+ const struct gvdb_hash_header *header;
+ guint32 n_bloom_words;
+ guint32 n_buckets;
+ gsize size;
+
+ header = gvdb_table_dereference (file, pointer, 4, &size);
+
+ if G_UNLIKELY (header == NULL || size < sizeof *header)
+ return;
+
+ size -= sizeof *header;
+
+ n_bloom_words = guint32_from_le (header->n_bloom_words);
+ n_buckets = guint32_from_le (header->n_buckets);
+ n_bloom_words &= (1u << 27) - 1;
+
+ if G_UNLIKELY (n_bloom_words * sizeof (guint32_le) > size)
+ return;
+
+ file->bloom_words = (gpointer) (header + 1);
+ size -= n_bloom_words * sizeof (guint32_le);
+ file->n_bloom_words = n_bloom_words;
+
+ if G_UNLIKELY (n_buckets > G_MAXUINT / sizeof (guint32_le) ||
+ n_buckets * sizeof (guint32_le) > size)
+ return;
+
+ file->hash_buckets = file->bloom_words + file->n_bloom_words;
+ size -= n_buckets * sizeof (guint32_le);
+ file->n_buckets = n_buckets;
+
+ if G_UNLIKELY (size % sizeof (struct gvdb_hash_item))
+ return;
+
+ file->hash_items = (gpointer) (file->hash_buckets + n_buckets);
+ file->n_hash_items = size / sizeof (struct gvdb_hash_item);
+}
+
+/**
+ * gvdb_table_new:
+ * @filename: the path to the hash file
+ * @trusted: if the contents of @filename are trusted
+ * @error: %NULL, or a pointer to a %NULL #GError
+ * @returns: a new #GvdbTable
+ *
+ * Creates a new #GvdbTable from the contents of the file found at
+ * @filename.
+ *
+ * The only time this function fails is if the file can not be opened.
+ * In that case, the #GError that is returned will be an error from
+ * g_mapped_file_new().
+ *
+ * An empty or otherwise corrupted file is considered to be a valid
+ * #GvdbTable with no entries.
+ *
+ * You should call gvdb_table_unref() on the return result when you no
+ * longer require it.
+ **/
+GvdbTable *
+gvdb_table_new (const gchar *filename,
+ gboolean trusted,
+ GError **error)
+{
+ GMappedFile *mapped;
+ GvdbTable *file;
+
+ if ((mapped = g_mapped_file_new (filename, FALSE, error)) == NULL)
+ return NULL;
+
+ file = g_slice_new0 (GvdbTable);
+ file->data = g_mapped_file_get_contents (mapped);
+ file->size = g_mapped_file_get_length (mapped);
+ file->trusted = trusted;
+ file->mapped = mapped;
+ file->ref_count = 1;
+
+ if (sizeof (struct gvdb_header) <= file->size)
+ {
+ const struct gvdb_header *header = (gpointer) file->data;
+
+ if (header->signature[0] == GVDB_SIGNATURE0 &&
+ header->signature[1] == GVDB_SIGNATURE1 &&
+ guint32_from_le (header->version) == 0)
+ file->byteswapped = FALSE;
+
+ else if (header->signature[0] == GVDB_SWAPPED_SIGNATURE0 &&
+ header->signature[1] == GVDB_SWAPPED_SIGNATURE1 &&
+ guint32_from_le (header->version) == 0)
+ file->byteswapped = TRUE;
+
+ else
+ {
+ g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL,
+ "%s: invalid header", filename);
+ g_slice_free (GvdbTable, file);
+ g_mapped_file_unref (mapped);
+
+ return NULL;
+ }
+
+ gvdb_table_setup_root (file, &header->root);
+ }
+
+ return file;
+}
+
+static gboolean
+gvdb_table_bloom_filter (GvdbTable *file,
+ guint32 hash_value)
+{
+ guint32 word, mask;
+
+ if (file->n_bloom_words == 0)
+ return TRUE;
+
+ word = (hash_value / 32) % file->n_bloom_words;
+ mask = 1 << (hash_value & 31);
+ mask |= 1 << ((hash_value >> file->bloom_shift) & 31);
+
+ return (guint32_from_le (file->bloom_words[word]) & mask) == mask;
+}
+
+static gboolean
+gvdb_table_check_name (GvdbTable *file,
+ struct gvdb_hash_item *item,
+ const gchar *key,
+ guint key_length)
+{
+ const gchar *this_key;
+ gsize this_size;
+ guint32 parent;
+
+ this_key = gvdb_table_item_get_key (file, item, &this_size);
+
+ if G_UNLIKELY (this_key == NULL || this_size > key_length)
+ return FALSE;
+
+ key_length -= this_size;
+
+ if G_UNLIKELY (memcmp (this_key, key + key_length, this_size) != 0)
+ return FALSE;
+
+ parent = guint32_from_le (item->parent);
+ if (key_length == 0 && parent == 0xffffffffu)
+ return TRUE;
+
+ if G_LIKELY (parent < file->n_hash_items && this_size > 0)
+ return gvdb_table_check_name (file,
+ &file->hash_items[parent],
+ key, key_length);
+
+ return FALSE;
+}
+
+static const struct gvdb_hash_item *
+gvdb_table_lookup (GvdbTable *file,
+ const gchar *key,
+ gchar type)
+{
+ guint32 hash_value = 5381;
+ guint key_length;
+ guint32 bucket;
+ guint32 lastno;
+ guint32 itemno;
+
+ if G_UNLIKELY (file->n_buckets == 0 || file->n_hash_items == 0)
+ return NULL;
+
+ for (key_length = 0; key[key_length]; key_length++)
+ hash_value = (hash_value * 33) + ((signed char *) key)[key_length];
+
+ if (!gvdb_table_bloom_filter (file, hash_value))
+ return NULL;
+
+ bucket = hash_value % file->n_buckets;
+ itemno = guint32_from_le (file->hash_buckets[bucket]);
+
+ if (bucket == file->n_buckets - 1 ||
+ (lastno = guint32_from_le(file->hash_buckets[bucket + 1])) > file->n_hash_items)
+ lastno = file->n_hash_items;
+
+ while G_LIKELY (itemno < lastno)
+ {
+ struct gvdb_hash_item *item = &file->hash_items[itemno];
+
+ if (hash_value == guint32_from_le (item->hash_value))
+ if G_LIKELY (gvdb_table_check_name (file, item, key, key_length))
+ if G_LIKELY (item->type == type)
+ return item;
+
+ itemno++;
+ }
+
+ return NULL;
+}
+
+static const struct gvdb_hash_item *
+gvdb_table_get_item (GvdbTable *table,
+ guint32_le item_no)
+{
+ guint32 item_no_native = guint32_from_le (item_no);
+
+ if G_LIKELY (item_no_native < table->n_hash_items)
+ return table->hash_items + item_no_native;
+
+ return NULL;
+}
+
+static gboolean
+gvdb_table_list_from_item (GvdbTable *table,
+ const struct gvdb_hash_item *item,
+ const guint32_le **list,
+ guint *length)
+{
+ gsize size;
+
+ *list = gvdb_table_dereference (table, &item->value.pointer, 4, &size);
+
+ if G_LIKELY (*list == NULL || size % 4)
+ return FALSE;
+
+ *length = size / 4;
+
+ return TRUE;
+}
+
+
+/**
+ * gvdb_table_list:
+ * @file: a #GvdbTable
+ * @key: a string
+ * @returns: a %NULL-terminated string array
+ *
+ * List all of the keys that appear below @key. The nesting of keys
+ * within the hash file is defined by the program that created the hash
+ * file. One thing is constant: each item in the returned array can be
+ * concatenated to @key to obtain the full name of that key.
+ *
+ * It is not possible to tell from this function if a given key is
+ * itself a path, a value, or another hash table; you are expected to
+ * know this for yourself.
+ *
+ * You should call g_strfreev() on the return result when you no longer
+ * require it.
+ **/
+gchar **
+gvdb_table_list (GvdbTable *file,
+ const gchar *key)
+{
+ const struct gvdb_hash_item *item;
+ const guint32_le *list;
+ gchar **strv;
+ guint length;
+ guint i;
+
+ if ((item = gvdb_table_lookup (file, key, 'L')) == NULL)
+ return NULL;
+
+ if (!gvdb_table_list_from_item (file, item, &list, &length))
+ return NULL;
+
+ strv = g_new (gchar *, length + 1);
+ for (i = 0; i < length; i++)
+ {
+ guint32 itemno = guint32_from_le (list[i]);
+
+ if (itemno < file->n_hash_items)
+ {
+ const struct gvdb_hash_item *item;
+ const gchar *string;
+ gsize strsize;
+
+ item = file->hash_items + itemno;
+
+ string = gvdb_table_item_get_key (file, item, &strsize);
+
+ if (string != NULL)
+ strv[i] = g_strndup (string, strsize);
+ else
+ strv[i] = g_malloc0 (1);
+ }
+ else
+ strv[i] = g_malloc0 (1);
+ }
+
+ strv[i] = NULL;
+
+ return strv;
+}
+
+/**
+ * gvdb_table_has_value:
+ * @file: a #GvdbTable
+ * @key: a string
+ * @returns: %TRUE if @key is in the table
+ *
+ * Checks for a value named @key in @file.
+ *
+ * Note: this function does not consider non-value nodes (other hash
+ * tables, for example).
+ **/
+gboolean
+gvdb_table_has_value (GvdbTable *file,
+ const gchar *key)
+{
+ return gvdb_table_lookup (file, key, 'v') != NULL;
+}
+
+static GVariant *
+gvdb_table_value_from_item (GvdbTable *table,
+ const struct gvdb_hash_item *item)
+{
+ GVariant *variant, *value;
+ gconstpointer data;
+ gsize size;
+
+ data = gvdb_table_dereference (table, &item->value.pointer, 8, &size);
+
+ if G_UNLIKELY (data == NULL)
+ return NULL;
+
+ variant = g_variant_new_from_data (G_VARIANT_TYPE_VARIANT,
+ data, size, table->trusted,
+ (GDestroyNotify) g_mapped_file_unref,
+ g_mapped_file_ref (table->mapped));
+ value = g_variant_get_variant (variant);
+ g_variant_unref (variant);
+
+ return value;
+}
+
+/**
+ * gvdb_table_get_value:
+ * @file: a #GvdbTable
+ * @key: a string
+ * @returns: a #GVariant, or %NULL
+ *
+ * Looks up a value named @key in @file.
+ *
+ * If the value is not found then %NULL is returned. Otherwise, a new
+ * #GVariant instance is returned. The #GVariant does not depend on the
+ * continued existence of @file.
+ *
+ * You should call g_variant_unref() on the return result when you no
+ * longer require it.
+ **/
+GVariant *
+gvdb_table_get_value (GvdbTable *file,
+ const gchar *key)
+{
+ const struct gvdb_hash_item *item;
+ GVariant *value;
+
+ if ((item = gvdb_table_lookup (file, key, 'v')) == NULL)
+ return NULL;
+
+ value = gvdb_table_value_from_item (file, item);
+
+ if (value && file->byteswapped)
+ {
+ GVariant *tmp;
+
+ tmp = g_variant_byteswap (value);
+ g_variant_unref (value);
+ value = tmp;
+ }
+
+ return value;
+}
+
+/**
+ * gvdb_table_get_raw_value:
+ * @table: a #GvdbTable
+ * @key: a string
+ * @returns: a #GVariant, or %NULL
+ *
+ * Looks up a value named @key in @file.
+ *
+ * This call is equivalent to gvdb_table_get_value() except that it
+ * never byteswaps the value.
+ **/
+GVariant *
+gvdb_table_get_raw_value (GvdbTable *table,
+ const gchar *key)
+{
+ const struct gvdb_hash_item *item;
+
+ if ((item = gvdb_table_lookup (table, key, 'v')) == NULL)
+ return NULL;
+
+ return gvdb_table_value_from_item (table, item);
+}
+
+/**
+ * gvdb_table_get_table:
+ * @file: a #GvdbTable
+ * @key: a string
+ * @returns: a new #GvdbTable, or %NULL
+ *
+ * Looks up the hash table named @key in @file.
+ *
+ * The toplevel hash table in a #GvdbTable can contain reference to
+ * child hash tables (and those can contain further references...).
+ *
+ * If @key is not found in @file then %NULL is returned. Otherwise, a
+ * new #GvdbTable is returned, referring to the child hashtable as
+ * contained in the file. This newly-created #GvdbTable does not depend
+ * on the continued existence of @file.
+ *
+ * You should call gvdb_table_unref() on the return result when you no
+ * longer require it.
+ **/
+GvdbTable *
+gvdb_table_get_table (GvdbTable *file,
+ const gchar *key)
+{
+ const struct gvdb_hash_item *item;
+ GvdbTable *new;
+
+ item = gvdb_table_lookup (file, key, 'H');
+
+ if (item == NULL)
+ return NULL;
+
+ new = g_slice_new0 (GvdbTable);
+ new->mapped = g_mapped_file_ref (file->mapped);
+ new->byteswapped = file->byteswapped;
+ new->trusted = file->trusted;
+ new->data = file->data;
+ new->size = file->size;
+ new->ref_count = 1;
+
+ gvdb_table_setup_root (new, &item->value.pointer);
+
+ return new;
+}
+
+/**
+ * gvdb_table_ref:
+ * @file: a #GvdbTable
+ * @returns: a new reference on @file
+ *
+ * Increases the reference count on @file.
+ **/
+GvdbTable *
+gvdb_table_ref (GvdbTable *file)
+{
+ g_atomic_int_inc (&file->ref_count);
+
+ return file;
+}
+
+/**
+ * gvdb_table_unref:
+ * @file: a #GvdbTable
+ *
+ * Decreases the reference count on @file, possibly freeing it.
+ *
+ * Since: 2.26
+ **/
+void
+gvdb_table_unref (GvdbTable *file)
+{
+ if (g_atomic_int_dec_and_test (&file->ref_count))
+ {
+ g_mapped_file_unref (file->mapped);
+ g_slice_free (GvdbTable, file);
+ }
+}
+
+/**
+ * gvdb_table_is_valid:
+ * @table: a #GvdbTable
+ * @returns: %TRUE if @table is still valid
+ *
+ * Checks if the table is still valid.
+ *
+ * An on-disk GVDB can be marked as invalid. This happens when the file
+ * has been replaced. The appropriate action is typically to reopen the
+ * file.
+ **/
+gboolean
+gvdb_table_is_valid (GvdbTable *table)
+{
+ return !!*table->data;
+}
+
+/**
+ * gvdb_table_walk:
+ * @table: a #GvdbTable
+ * @key: a key corresponding to a list
+ * @open_func: the #GvdbWalkOpenFunc
+ * @value_func: the #GvdbWalkValueFunc
+ * @close_func: the #GvdbWalkCloseFunc
+ * @user_data: data to pass to the callbacks
+ *
+ * Looks up the list at @key and iterate over the items in it.
+ *
+ * First, @open_func is called to signal that we are starting to iterate over
+ * the list. Then the list is iterated. When all items in the list have been
+ * iterated over, the @close_func is called.
+ *
+ * When iterating, if a given item in the list is a value then @value_func is
+ * called.
+ *
+ * If a given item in the list is itself a list then @open_func is called. If
+ * that function returns %TRUE then the walk begins iterating the items in the
+ * sublist, until there are no more items, at which point a matching
+ * @close_func call is made. If @open_func returns %FALSE then no iteration of
+ * the sublist occurs and no corresponding @close_func call is made.
+ **/
+void
+gvdb_table_walk (GvdbTable *table,
+ const gchar *key,
+ GvdbWalkOpenFunc open_func,
+ GvdbWalkValueFunc value_func,
+ GvdbWalkCloseFunc close_func,
+ gpointer user_data)
+{
+ const struct gvdb_hash_item *item;
+ const guint32_le *pointers[64];
+ const guint32_le *enders[64];
+ gsize name_lengths[64];
+ gint index = 0;
+
+ item = gvdb_table_lookup (table, key, 'L');
+ name_lengths[0] = 0;
+ pointers[0] = NULL;
+ enders[0] = NULL;
+ goto start_here;
+
+ while (index)
+ {
+ close_func (name_lengths[index], user_data);
+ index--;
+
+ while (pointers[index] < enders[index])
+ {
+ const gchar *name;
+ gsize name_len;
+
+ item = gvdb_table_get_item (table, *pointers[index]++);
+ start_here:
+
+ if (item != NULL &&
+ (name = gvdb_table_item_get_key (table, item, &name_len)))
+ {
+ if (item->type == 'L')
+ {
+ if (open_func (name, name_len, user_data))
+ {
+ guint length;
+
+ index++;
+ g_assert (index < 64);
+
+ gvdb_table_list_from_item (table, item,
+ &pointers[index],
+ &length);
+ enders[index] = pointers[index] + length;
+ name_lengths[index] = name_len;
+ }
+ }
+ else if (item->type == 'v')
+ {
+ GVariant *value;
+
+ value = gvdb_table_value_from_item (table, item);
+
+ if (value != NULL)
+ {
+ if (table->byteswapped)
+ {
+ GVariant *tmp;
+
+ tmp = g_variant_byteswap (value);
+ g_variant_unref (value);
+ value = tmp;
+ }
+
+ value_func (name, name_len, value, user_data);
+ g_variant_unref (value);
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/rootfs-manager/gvdb/gvdb-reader.h b/rootfs-manager/gvdb/gvdb-reader.h
new file mode 100644
index 0000000..e6921e9
--- /dev/null
+++ b/rootfs-manager/gvdb/gvdb-reader.h
@@ -0,0 +1,80 @@
+/*
+ * Copyright  2010 Codethink Limited
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the licence, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Ryan Lortie <desrt desrt ca>
+ */
+
+#ifndef __gvdb_reader_h__
+#define __gvdb_reader_h__
+
+#include <glib.h>
+
+typedef struct _GvdbTable GvdbTable;
+
+G_BEGIN_DECLS
+
+G_GNUC_INTERNAL
+GvdbTable * gvdb_table_new (const gchar *filename,
+ gboolean trusted,
+ GError **error);
+G_GNUC_INTERNAL
+GvdbTable * gvdb_table_ref (GvdbTable *table);
+G_GNUC_INTERNAL
+void gvdb_table_unref (GvdbTable *table);
+
+G_GNUC_INTERNAL
+gchar ** gvdb_table_list (GvdbTable *table,
+ const gchar *key);
+G_GNUC_INTERNAL
+GvdbTable * gvdb_table_get_table (GvdbTable *table,
+ const gchar *key);
+G_GNUC_INTERNAL
+GVariant * gvdb_table_get_raw_value (GvdbTable *table,
+ const gchar *key);
+G_GNUC_INTERNAL
+GVariant * gvdb_table_get_value (GvdbTable *table,
+ const gchar *key);
+
+G_GNUC_INTERNAL
+gboolean gvdb_table_has_value (GvdbTable *table,
+ const gchar *key);
+
+G_GNUC_INTERNAL
+gboolean gvdb_table_is_valid (GvdbTable *table);
+
+typedef void (*GvdbWalkValueFunc) (const gchar *name,
+ gsize name_len,
+ GVariant *value,
+ gpointer user_data);
+typedef gboolean (*GvdbWalkOpenFunc) (const gchar *name,
+ gsize name_len,
+ gpointer user_data);
+typedef void (*GvdbWalkCloseFunc) (gsize name_len,
+ gpointer user_data);
+
+G_GNUC_INTERNAL
+void gvdb_table_walk (GvdbTable *table,
+ const gchar *key,
+ GvdbWalkOpenFunc open_func,
+ GvdbWalkValueFunc value_func,
+ GvdbWalkCloseFunc close_func,
+ gpointer user_data);
+
+G_END_DECLS
+
+#endif /* __gvdb_reader_h__ */
diff --git a/rootfs-manager/gvdb/gvdb.doap b/rootfs-manager/gvdb/gvdb.doap
new file mode 100644
index 0000000..b4ae60c
--- /dev/null
+++ b/rootfs-manager/gvdb/gvdb.doap
@@ -0,0 +1,32 @@
+<?xml version='1.0' encoding='utf-8'?>
+
+<Project xmlns='http://usefulinc.com/ns/doap#'
+ xmlns:foaf='http://xmlns.com/foaf/0.1/'
+ xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
+ xmlns:gnome='http://api.gnome.org/doap-extensions#'>
+
+ <name xml:lang='en'>gvdb</name>
+ <shortdesc xml:lang='en'>GVariant Database file</shortdesc>
+ <description xml:lang='en'>
+ A simple database file format that stores a mapping from strings to
+ GVariant values in a way that is extremely efficient for lookups.
+
+ The database is written once and can not be modified.
+
+ Included here is reader code and a first-pass implementation of a
+ writer (that does not currently produce particularly optimised
+ output).
+
+ It is intended that this code be used by copy-pasting into your
+ project or by making use of git-merge(1).
+ </description>
+
+ <maintainer>
+ <foaf:Person>
+ <foaf:name>Ryan Lortie</foaf:name>
+ <foaf:mbox rdf:resource='mailto:desrt desrt ca'/>
+ <gnome:userid>ryanl</gnome:userid>
+ </foaf:Person>
+ </maintainer>
+
+</Project>
diff --git a/rootfs-manager/jhbuild-rootfs-manager.c b/rootfs-manager/jhbuild-rootfs-manager.c
new file mode 100644
index 0000000..572b49b
--- /dev/null
+++ b/rootfs-manager/jhbuild-rootfs-manager.c
@@ -0,0 +1,151 @@
+#include <glib.h>
+
+#include <gio/gunixfdlist.h>
+
+typedef struct {
+ GDBusConnection *system_bus;
+
+ char *root;
+} JhbuildInstallHelper;
+
+static GDBusNodeInfo *introspection_data = NULL;
+
+static const gchar introspection_xml[] =
+ "<node>"
+ " <interface name='org.gnome.JhbuildInstallHelper'>"
+ " <method name='RootRebase'>"
+ " <annotation name='org.gtk.GDBus.Annotation' value='OnMethod'/>"
+ " <arg type='s' name='rootid' direction='in'/>"
+ " </method>"
+ " <method name='RootUpdateWithArtifact'>"
+ " <annotation name='org.gtk.GDBus.Annotation' value='OnMethod'/>"
+ " <arg type='s' name='rootid' direction='in'/>"
+ " <arg type='h' name='tardata' direction='in'/>"
+ " </method>"
+ " </interface>"
+ "</node>";
+
+static gboolean
+root_update_with_artifact (JhbuildInstallHelper *helper,
+ const char *rootid,
+ int tar_fd,
+ GError **error)
+{
+ GPtrArray *argv;
+ int estatus;
+
+ argv = g_ptr_array_new ();
+ g_ptr_array_add (argv, "tar");
+ g_ptr_array_add (argv, "x");
+ g_ptr_array_add (argv, NULL);
+ return g_spawn_sync (helper->root, argv, NULL,
+ G_SPAWN_SEARCH_PATH,
+ NULL, NULL, NULL, NULL &estatus, error);
+}
+
+static void
+handle_method_call (GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *method_name,
+ GVariant *parameters,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ GDBusMessage *message;
+ GError *error = NULL;
+
+ message = g_dbus_method_invocation_get_message (invocation);
+ if (g_strcmp0 (method_name, "RootUpdateWithArtifact") == 0)
+ {
+ const gchar *rootid;
+ gint32 tar_fd_id;
+ int tar_fd;
+ GUnixFDList *fd_list;
+
+ g_variant_get (parameters, "(&sh)", &rootid, &tar_fd);
+ fd_list = g_dbus_message_get_unix_fd_list (message);
+ g_assert (fd_list != NULL);
+
+ tar_fd = g_unix_fd_list_get (fd_list, tar_fd_id, &error);
+ if (tar_fd == -1)
+ g_dbus_method_invocation_take_error (invocation, error);
+ else
+ {
+ if (!root_update_with_artifact (user_data, rootid, tar_fd, &error))
+ g_dbus_method_invocation_take_error (invocation, error);
+ else
+ g_dbus_method_invocation_return_value (invocation, NULL);
+ }
+ }
+}
+
+static void
+on_bus_acquired (GDBusConnection *connection,
+ const char *name,
+ gpointer user_data)
+{
+ JhbuildInstallHelper *helper = user_data;
+
+ helper->system_bus = g_object_ref (connection);
+}
+
+static void
+on_name_acquired (GDBusConnection *connection,
+ const char *name,
+ gpointer user_data)
+{
+ JhbuildInstallHelper *helper = user_data;
+
+
+}
+
+static void
+on_name_lost (GDBusConnection *connection,
+ const char *name,
+ gpointer user_data)
+{
+ JhbuildInstallHelper *helper = user_data;
+
+ if (connection)
+ exit (0);
+}
+
+static void
+install_helper_run (JhbuildInstallHelper *helper)
+{
+ GError *error = NULL;
+
+ helper->system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
+ if (!helper->system_bus)
+ g_error ("%s", error->message);
+
+ g_bus_own_name (G_BUS_TYPE_SYSTEM,
+ "org.gnome.JhbuildInstallHelper",
+ G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT,
+ on_bus_acquired,
+ on_name_acquired,
+ on_name_lost,
+ helper,
+ NULL);
+}
+
+int
+main (int argc,
+ char **argv,
+ char **envp)
+{
+ GMainLoop *loop;
+ JhbuildInstallHelper helper;
+
+ g_type_init ();
+
+ loop = g_main_loop_new (NULL, TRUE);
+
+ install_helper_run (&helper);
+
+ g_main_loop_run (loop);
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]