diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2011-04-05 14:03:08 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2011-04-05 20:01:57 +0100 |
commit | 13d8963d8c0203e1f72c519e5acf79ebf7cccb4c (patch) | |
tree | 0699b86ada86e692a24294e7ca719d18c702e13e /inspector | |
parent | 9e7c6a548353bde925c16434711bcc6208038d83 (diff) | |
download | libguestfs-13d8963d8c0203e1f72c519e5acf79ebf7cccb4c.tar.gz libguestfs-13d8963d8c0203e1f72c519e5acf79ebf7cccb4c.tar.xz libguestfs-13d8963d8c0203e1f72c519e5acf79ebf7cccb4c.zip |
New API: inspect-get-drive-mappings
This returns the drive mappings from the Windows Registry.
virt-inspector displays the drive mappings, giving output
similar to this:
<drive_mappings>
<drive_mapping name="C">/dev/sda2</drive_mapping>
<drive_mapping name="E">/dev/sdb1</drive_mapping>
</drive_mappings>
Diffstat (limited to 'inspector')
-rw-r--r-- | inspector/example-windows.xml | 3 | ||||
-rw-r--r-- | inspector/virt-inspector.c | 54 | ||||
-rw-r--r-- | inspector/virt-inspector.rng | 13 |
3 files changed, 70 insertions, 0 deletions
diff --git a/inspector/example-windows.xml b/inspector/example-windows.xml index 8e53159a..8b3b8a70 100644 --- a/inspector/example-windows.xml +++ b/inspector/example-windows.xml @@ -20,6 +20,9 @@ <type>ntfs</type> </filesystem> </filesystems> + <drive_mappings> + <drive_mapping name="C">/dev/sda2</drive_mapping> + </drive_mappings> <applications> <application> <name>test1</name> diff --git a/inspector/virt-inspector.c b/inspector/virt-inspector.c index d016b2dd..7724be65 100644 --- a/inspector/virt-inspector.c +++ b/inspector/virt-inspector.c @@ -51,6 +51,7 @@ static void output_roots (xmlTextWriterPtr xo, char **roots); static void output_root (xmlTextWriterPtr xo, char *root); static void output_mountpoints (xmlTextWriterPtr xo, char *root); static void output_filesystems (xmlTextWriterPtr xo, char *root); +static void output_drive_mappings (xmlTextWriterPtr xo, char *root); static void output_applications (xmlTextWriterPtr xo, char *root); static void canonicalize (char *dev); static void free_strings (char **argv); @@ -458,6 +459,8 @@ output_root (xmlTextWriterPtr xo, char *root) output_filesystems (xo, root); + output_drive_mappings (xo, root); + output_applications (xo, root); XMLERROR (-1, xmlTextWriterEndElement (xo)); @@ -473,6 +476,15 @@ compare_keys (const void *p1, const void *p2) } static int +compare_keys_nocase (const void *p1, const void *p2) +{ + const char *key1 = * (char * const *) p1; + const char *key2 = * (char * const *) p2; + + return strcasecmp (key1, key2); +} + +static int compare_keys_len (const void *p1, const void *p2) { const char *key1 = * (char * const *) p1; @@ -583,6 +595,48 @@ output_filesystems (xmlTextWriterPtr xo, char *root) } static void +output_drive_mappings (xmlTextWriterPtr xo, char *root) +{ + char **drive_mappings = NULL; + size_t i; + + DISABLE_GUESTFS_ERRORS_FOR ( + drive_mappings = guestfs_inspect_get_drive_mappings (g, root); + ); + if (drive_mappings == NULL) + return; + + if (drive_mappings[0] == NULL) { + free_strings (drive_mappings); + return; + } + + /* Sort by key. */ + qsort (drive_mappings, + count_strings (drive_mappings) / 2, 2 * sizeof (char *), + compare_keys_nocase); + + XMLERROR (-1, xmlTextWriterStartElement (xo, BAD_CAST "drive_mappings")); + + for (i = 0; drive_mappings[i] != NULL; i += 2) { + canonicalize (drive_mappings[i+1]); + + XMLERROR (-1, + xmlTextWriterStartElement (xo, BAD_CAST "drive_mapping")); + XMLERROR (-1, + xmlTextWriterWriteAttribute (xo, BAD_CAST "name", + BAD_CAST drive_mappings[i])); + XMLERROR (-1, + xmlTextWriterWriteString (xo, BAD_CAST drive_mappings[i+1])); + XMLERROR (-1, xmlTextWriterEndElement (xo)); + } + + XMLERROR (-1, xmlTextWriterEndElement (xo)); + + free_strings (drive_mappings); +} + +static void output_applications (xmlTextWriterPtr xo, char *root) { struct guestfs_application_list *apps; diff --git a/inspector/virt-inspector.rng b/inspector/virt-inspector.rng index 7a822e68..669e8bc6 100644 --- a/inspector/virt-inspector.rng +++ b/inspector/virt-inspector.rng @@ -47,6 +47,7 @@ <ref name="mountpoints"/> <ref name="filesystems"/> + <optional><ref name="drive_mappings"/></optional> <optional><ref name="applications"/></optional> </interleave> @@ -83,6 +84,18 @@ </element> </define> + <!-- drive mappings (for Windows) --> + <define name="drive_mappings"> + <element name="drive_mappings"> + <oneOrMore> + <element name="drive_mapping"> + <attribute name="name"><text/></attribute> + <text/> + </element> + </oneOrMore> + </element> + </define> + <!-- applications installed --> <define name="applications"> <element name="applications"> |