[virt-tools-list] [PATCH 3/7] Also extract application ID from ISO PVD

Daniel P. Berrange berrange at redhat.com
Tue Feb 21 13:50:13 UTC 2012


From: "Daniel P. Berrange" <berrange at redhat.com>

---
 osinfo/libosinfo.syms  |    1 +
 osinfo/osinfo_db.c     |    7 +++++-
 osinfo/osinfo_loader.c |    4 ++-
 osinfo/osinfo_media.c  |   56 +++++++++++++++++++++++++++++++++++++++++++++++-
 osinfo/osinfo_media.h  |    2 +
 5 files changed, 67 insertions(+), 3 deletions(-)

diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index d4a6124..f4f6337 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -156,6 +156,7 @@ LIBOSINFO_0.0.1 {
 	osinfo_media_get_volume_id;
 	osinfo_media_get_system_id;
 	osinfo_media_get_publisher_id;
+	osinfo_media_get_application_id;
         osinfo_media_get_kernel_path;
         osinfo_media_get_initrd_path;
 	osinfo_medialist_get_type;
diff --git a/osinfo/osinfo_db.c b/osinfo/osinfo_db.c
index b5ac506..ecc8fbd 100644
--- a/osinfo/osinfo_db.c
+++ b/osinfo/osinfo_db.c
@@ -360,6 +360,7 @@ OsinfoOs *osinfo_db_guess_os_from_media(OsinfoDb *db,
     const gchar *media_volume;
     const gchar *media_system;
     const gchar *media_publisher;
+    const gchar *media_application;
 
     g_return_val_if_fail(OSINFO_IS_DB(db), NULL);
     g_return_val_if_fail(media != NULL, NULL);
@@ -367,6 +368,7 @@ OsinfoOs *osinfo_db_guess_os_from_media(OsinfoDb *db,
     media_volume = osinfo_media_get_volume_id(media);
     media_system = osinfo_media_get_system_id(media);
     media_publisher = osinfo_media_get_publisher_id(media);
+    media_application = osinfo_media_get_application_id(media);
 
     oss = osinfo_list_get_elements(OSINFO_LIST(db->priv->oses));
     for (os_iter = oss; os_iter; os_iter = os_iter->next) {
@@ -382,8 +384,11 @@ OsinfoOs *osinfo_db_guess_os_from_media(OsinfoDb *db,
             const gchar *os_volume = osinfo_media_get_volume_id(os_media);
             const gchar *os_system = osinfo_media_get_system_id(os_media);
             const gchar *os_publisher = osinfo_media_get_publisher_id(os_media);
+            const gchar *os_application = osinfo_media_get_application_id(os_media);
 
-            if (match_regex (os_volume, media_volume) &&
+            if ((match_regex (os_volume, media_volume) ||
+                 match_regex (os_application, media_application))
+                 &&
                 (match_regex (os_system, media_system) ||
                  match_regex (os_publisher, media_publisher))) {
                 ret = os;
diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index 130472a..c44095b 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -530,7 +530,9 @@ static OsinfoMedia *osinfo_loader_media (OsinfoLoader *loader,
              strcmp((const gchar *)nodes[i]->name,
                     OSINFO_MEDIA_PROP_SYSTEM_ID) != 0 &&
              strcmp((const gchar *)nodes[i]->name,
-                    OSINFO_MEDIA_PROP_PUBLISHER_ID) != 0))
+                    OSINFO_MEDIA_PROP_PUBLISHER_ID) != 0 &&
+             strcmp((const gchar *)nodes[i]->name,
+                    OSINFO_MEDIA_PROP_APPLICATION_ID) != 0))
             continue;
 
         osinfo_entity_set_param(OSINFO_ENTITY(media),
diff --git a/osinfo/osinfo_media.c b/osinfo/osinfo_media.c
index 53d362c..723b205 100644
--- a/osinfo/osinfo_media.c
+++ b/osinfo/osinfo_media.c
@@ -31,6 +31,7 @@
 #define MAX_VOLUME 32
 #define MAX_SYSTEM 32
 #define MAX_PUBLISHER 128
+#define MAX_APPLICATION 128
 
 #define PVD_OFFSET 0x00008000
 #define BOOTABLE_TAG "EL TORITO SPECIFICATION"
@@ -43,7 +44,9 @@ struct _PrimaryVolumeDescriptor {
     gchar  volume[MAX_VOLUME];       /* Volume ID */
     guint8 ignored2[246];
     gchar  publisher[MAX_PUBLISHER]; /* Publisher ID */
-    guint8 ignored3[1602];
+    guint8 ignored3[128];
+    gchar  application[MAX_APPLICATION]; /* Application ID */
+    guint8 ignored4[1346];
 } __attribute__ ((packed));
 
 /* the PrimaryVolumeDescriptor struct must exactly 2048 bytes long
@@ -137,6 +140,7 @@ enum {
     PROP_URL,
     PROP_VOLUME_ID,
     PROP_PUBLISHER_ID,
+    PROP_APPLICATION_ID,
     PROP_SYSTEM_ID,
     PROP_KERNEL_PATH,
     PROP_INITRD_PATH,
@@ -173,6 +177,11 @@ osinfo_media_get_property (GObject    *object,
                             osinfo_media_get_publisher_id (media));
         break;
 
+    case PROP_APPLICATION_ID:
+        g_value_set_string (value,
+                            osinfo_media_get_application_id (media));
+        break;
+
     case PROP_SYSTEM_ID:
         g_value_set_string (value,
                             osinfo_media_get_system_id (media));
@@ -249,6 +258,12 @@ osinfo_media_set_property(GObject      *object,
                                  g_value_get_string (value));
         break;
 
+    case PROP_APPLICATION_ID:
+        osinfo_entity_set_param (OSINFO_ENTITY(media),
+                                 OSINFO_MEDIA_PROP_APPLICATION_ID,
+                                 g_value_get_string (value));
+        break;
+
     case PROP_SYSTEM_ID:
         osinfo_entity_set_param (OSINFO_ENTITY(media),
                                  OSINFO_MEDIA_PROP_SYSTEM_ID,
@@ -366,6 +381,21 @@ osinfo_media_class_init (OsinfoMediaClass *klass)
     g_object_class_install_property (g_klass, PROP_PUBLISHER_ID, pspec);
 
     /**
+     * OsinfoMedia::application-id
+     *
+     * Expected application ID (regular expression) for ISO9660 image/device.
+     */
+    pspec = g_param_spec_string ("application-id",
+                                 "ApplicationID",
+                                 "Expected ISO9660 application ID",
+                                 NULL /* default value */,
+                                 G_PARAM_READWRITE |
+                                 G_PARAM_STATIC_NAME |
+                                 G_PARAM_STATIC_NICK |
+                                 G_PARAM_STATIC_BLURB);
+    g_object_class_install_property (g_klass, PROP_APPLICATION_ID, pspec);
+
+    /**
      * OsinfoMedia::system-id
      *
      * Expected system ID (regular expression) for ISO9660 image/device.
@@ -593,6 +623,10 @@ static void on_svd_read (GObject *source,
         osinfo_entity_set_param(OSINFO_ENTITY(ret),
                                 OSINFO_MEDIA_PROP_PUBLISHER_ID,
                                 data->pvd.publisher);
+    if (!is_str_empty (data->pvd.application))
+        osinfo_entity_set_param(OSINFO_ENTITY(ret),
+                                OSINFO_MEDIA_PROP_APPLICATION_ID,
+                                data->pvd.application);
 
 EXIT:
     if (error != NULL)
@@ -632,6 +666,7 @@ static void on_pvd_read (GObject *source,
     data->pvd.volume[MAX_VOLUME - 1] = 0;
     data->pvd.system[MAX_SYSTEM - 1] = 0;
     data->pvd.publisher[MAX_PUBLISHER - 1] = 0;
+    data->pvd.application[MAX_APPLICATION - 1] = 0;
 
     if (is_str_empty(data->pvd.volume)) {
         g_set_error(&error,
@@ -864,6 +899,25 @@ const gchar *osinfo_media_get_publisher_id(OsinfoMedia *media)
 }
 
 /**
+ * osinfo_media_get_application_id:
+ * @media: a #OsinfoMedia instance
+ *
+ * If @media is an ISO9660 image/device, this function retrieves the expected
+ * application ID.
+ *
+ * Note: In practice, this will usually not be the exact copy of the application
+ * ID string on the ISO image/device but rather a regular expression that
+ * matches it.
+ *
+ * Returns: (transfer none): the application id, or NULL
+ */
+const gchar *osinfo_media_get_application_id(OsinfoMedia *media)
+{
+    return osinfo_entity_get_param_value(OSINFO_ENTITY(media),
+                                         OSINFO_MEDIA_PROP_APPLICATION_ID);
+}
+
+/**
  * osinfo_media_get_kernel_path:
  * @media: a #OsinfoMedia instance
  *
diff --git a/osinfo/osinfo_media.h b/osinfo/osinfo_media.h
index b6a0ee1..a859438 100644
--- a/osinfo/osinfo_media.h
+++ b/osinfo/osinfo_media.h
@@ -75,6 +75,7 @@ typedef struct _OsinfoMediaPrivate OsinfoMediaPrivate;
 #define OSINFO_MEDIA_PROP_VOLUME_ID    "volume-id"
 #define OSINFO_MEDIA_PROP_SYSTEM_ID    "system-id"
 #define OSINFO_MEDIA_PROP_PUBLISHER_ID "publisher-id"
+#define OSINFO_MEDIA_PROP_APPLICATION_ID "application-id"
 #define OSINFO_MEDIA_PROP_KERNEL       "kernel"
 #define OSINFO_MEDIA_PROP_INITRD       "initrd"
 #define OSINFO_MEDIA_PROP_LIVE         "live"
@@ -118,6 +119,7 @@ const gchar *osinfo_media_get_url(OsinfoMedia *media);
 const gchar *osinfo_media_get_volume_id(OsinfoMedia *media);
 const gchar *osinfo_media_get_system_id(OsinfoMedia *media);
 const gchar *osinfo_media_get_publisher_id(OsinfoMedia *media);
+const gchar *osinfo_media_get_application_id(OsinfoMedia *media);
 const gchar *osinfo_media_get_kernel_path(OsinfoMedia *media);
 const gchar *osinfo_media_get_initrd_path(OsinfoMedia *media);
 gboolean osinfo_media_get_installer(OsinfoMedia *media);
-- 
1.7.7.6




More information about the virt-tools-list mailing list