summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-03-16 13:28:13 +0000
committerRichard W.M. Jones <rjones@redhat.com>2012-03-16 14:40:20 +0000
commita43f35f5bb7c40b000083cd8be5cb1f28595a3f1 (patch)
tree0b345ec127c074fc51a18b28a8c6b036fd3a2293
parentd17218c2107ada5e8e1c011fa51ed88b4873d9ef (diff)
downloadlibguestfs-a43f35f5bb7c40b000083cd8be5cb1f28595a3f1.tar.gz
libguestfs-a43f35f5bb7c40b000083cd8be5cb1f28595a3f1.tar.xz
libguestfs-a43f35f5bb7c40b000083cd8be5cb1f28595a3f1.zip
New APIs: isoinfo and isoinfo-device.
Get ISO primary volume descriptor information for either ISO devices or ISO files.
-rw-r--r--.gitignore1
-rw-r--r--daemon/Makefile.am1
-rw-r--r--daemon/isoinfo.c292
-rw-r--r--generator/generator_actions.ml32
-rw-r--r--generator/generator_structs.ml22
-rw-r--r--java/Makefile.inc1
-rw-r--r--po/POTFILES.in1
-rw-r--r--src/MAX_PROC_NR2
8 files changed, 351 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index f6c42a21..e0d71c84 100644
--- a/.gitignore
+++ b/.gitignore
@@ -183,6 +183,7 @@ java/com_redhat_et_libguestfs_GuestFS.h
java/com/redhat/et/libguestfs/GuestFS.java
java/com/redhat/et/libguestfs/INotifyEvent.java
java/com/redhat/et/libguestfs/IntBool.java
+java/com/redhat/et/libguestfs/ISOInfo.java
java/com/redhat/et/libguestfs/LV.java
java/com/redhat/et/libguestfs/Partition.java
java/com/redhat/et/libguestfs/PV.java
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index 74d24fcf..02c21df9 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -125,6 +125,7 @@ guestfsd_SOURCES = \
inotify.c \
internal.c \
is.c \
+ isoinfo.c \
labels.c \
link.c \
ls.c \
diff --git a/daemon/isoinfo.c b/daemon/isoinfo.c
new file mode 100644
index 00000000..c0ee1c9a
--- /dev/null
+++ b/daemon/isoinfo.c
@@ -0,0 +1,292 @@
+/* libguestfs - the guestfsd daemon
+ * Copyright (C) 2012 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <inttypes.h>
+#include <string.h>
+#include <unistd.h>
+#include <time.h>
+
+#include "guestfs_protocol.h"
+#include "daemon.h"
+#include "actions.h"
+
+static int
+parse_uint32 (uint32_t *ret, const char *str)
+{
+ uint32_t r;
+
+ if (sscanf (str, "%" SCNu32, &r) != 1) {
+ reply_with_error ("cannot parse numeric field from isoinfo: %s", str);
+ return -1;
+ }
+
+ *ret = r;
+ return 0;
+}
+
+/* This is always in a fixed format:
+ * "2012 03 16 11:05:46.00"
+ * or if the field is not present, then:
+ * "0000 00 00 00:00:00.00"
+ */
+static int
+parse_time_t (int64_t *ret, const char *str)
+{
+ struct tm tm;
+ time_t r;
+
+ if (STREQ (str, "0000 00 00 00:00:00.00")) {
+ *ret = -1;
+ return 0;
+ }
+
+ if (sscanf (str, "%04d %02d %02d %02d:%02d:%02d",
+ &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
+ &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) {
+ reply_with_error ("cannot parse date from isoinfo: %s", str);
+ return -1;
+ }
+
+ /* Adjust fields. */
+ tm.tm_year -= 1900;
+ tm.tm_mon--;
+ tm.tm_isdst = -1;
+
+ /* Convert to time_t. */
+ r = timegm (&tm);
+ if (r == -1) {
+ reply_with_error ("invalid date or time: %s", str);
+ return -1;
+ }
+
+ *ret = r;
+ return 0;
+}
+
+static guestfs_int_isoinfo *
+parse_isoinfo (char **lines)
+{
+ guestfs_int_isoinfo *ret;
+ size_t i;
+
+ ret = calloc (1, sizeof *ret);
+ if (ret == NULL) {
+ reply_with_perror ("calloc");
+ return NULL;
+ }
+
+ /* Default each int field in the struct to -1. */
+ ret->iso_volume_space_size = (uint32_t) -1;
+ ret->iso_volume_set_size = (uint32_t) -1;
+ ret->iso_volume_sequence_number = (uint32_t) -1;
+ ret->iso_logical_block_size = (uint32_t) -1;
+ ret->iso_volume_creation_t = -1;
+ ret->iso_volume_modification_t = -1;
+ ret->iso_volume_expiration_t = -1;
+ ret->iso_volume_effective_t = -1;
+
+ for (i = 0; lines[i] != NULL; ++i) {
+ if (STRPREFIX (lines[i], "System id: ")) {
+ ret->iso_system_id = strdup (&lines[i][11]);
+ if (ret->iso_system_id == NULL) goto error;
+ }
+ else if (STRPREFIX (lines[i], "Volume id: ")) {
+ ret->iso_volume_id = strdup (&lines[i][11]);
+ if (ret->iso_volume_id == NULL) goto error;
+ }
+ else if (STRPREFIX (lines[i], "Volume set id: ")) {
+ ret->iso_volume_set_id = strdup (&lines[i][15]);
+ if (ret->iso_volume_set_id == NULL) goto error;
+ }
+ else if (STRPREFIX (lines[i], "Publisher id: ")) {
+ ret->iso_publisher_id = strdup (&lines[i][14]);
+ if (ret->iso_publisher_id == NULL) goto error;
+ }
+ else if (STRPREFIX (lines[i], "Data preparer id: ")) {
+ ret->iso_data_preparer_id = strdup (&lines[i][18]);
+ if (ret->iso_data_preparer_id == NULL) goto error;
+ }
+ else if (STRPREFIX (lines[i], "Application id: ")) {
+ ret->iso_application_id = strdup (&lines[i][16]);
+ if (ret->iso_application_id == NULL) goto error;
+ }
+ else if (STRPREFIX (lines[i], "Copyright File id: ")) {
+ ret->iso_copyright_file_id = strdup (&lines[i][19]);
+ if (ret->iso_copyright_file_id == NULL) goto error;
+ }
+ else if (STRPREFIX (lines[i], "Abstract File id: ")) {
+ ret->iso_abstract_file_id = strdup (&lines[i][18]);
+ if (ret->iso_abstract_file_id == NULL) goto error;
+ }
+ else if (STRPREFIX (lines[i], "Bibliographic File id: ")) {
+ ret->iso_bibliographic_file_id = strdup (&lines[i][23]);
+ if (ret->iso_bibliographic_file_id == NULL) goto error;
+ }
+ else if (STRPREFIX (lines[i], "Volume size is: ")) {
+ if (parse_uint32 (&ret->iso_volume_space_size, &lines[i][16]) == -1)
+ goto error;
+ }
+ else if (STRPREFIX (lines[i], "Volume set size is: ")) {
+ if (parse_uint32 (&ret->iso_volume_set_size, &lines[i][20]) == -1)
+ goto error;
+ }
+ else if (STRPREFIX (lines[i], "Volume set sequence number is: ")) {
+ if (parse_uint32 (&ret->iso_volume_sequence_number, &lines[i][31]) == -1)
+ goto error;
+ }
+ else if (STRPREFIX (lines[i], "Logical block size is: ")) {
+ if (parse_uint32 (&ret->iso_logical_block_size, &lines[i][23]) == -1)
+ goto error;
+ }
+ else if (STRPREFIX (lines[i], "Creation Date: ")) {
+ if (parse_time_t (&ret->iso_volume_creation_t, &lines[i][19]) == -1)
+ goto error;
+ }
+ else if (STRPREFIX (lines[i], "Modification Date: ")) {
+ if (parse_time_t (&ret->iso_volume_modification_t, &lines[i][19]) == -1)
+ goto error;
+ }
+ else if (STRPREFIX (lines[i], "Expiration Date: ")) {
+ if (parse_time_t (&ret->iso_volume_expiration_t, &lines[i][19]) == -1)
+ goto error;
+ }
+ else if (STRPREFIX (lines[i], "Effective Date: ")) {
+ if (parse_time_t (&ret->iso_volume_effective_t, &lines[i][19]) == -1)
+ goto error;
+ }
+ }
+
+ /* Any string fields which were not set above will be NULL. However
+ * we cannot return NULL fields in structs, so we convert these to
+ * empty strings here.
+ */
+ if (ret->iso_system_id == NULL) {
+ ret->iso_system_id = strdup ("");
+ if (ret->iso_system_id == NULL) goto error;
+ }
+ if (ret->iso_volume_id == NULL) {
+ ret->iso_volume_id = strdup ("");
+ if (ret->iso_volume_id == NULL) goto error;
+ }
+ if (ret->iso_volume_set_id == NULL) {
+ ret->iso_volume_set_id = strdup ("");
+ if (ret->iso_volume_set_id == NULL) goto error;
+ }
+ if (ret->iso_publisher_id == NULL) {
+ ret->iso_publisher_id = strdup ("");
+ if (ret->iso_publisher_id == NULL) goto error;
+ }
+ if (ret->iso_data_preparer_id == NULL) {
+ ret->iso_data_preparer_id = strdup ("");
+ if (ret->iso_data_preparer_id == NULL) goto error;
+ }
+ if (ret->iso_application_id == NULL) {
+ ret->iso_application_id = strdup ("");
+ if (ret->iso_application_id == NULL) goto error;
+ }
+ if (ret->iso_copyright_file_id == NULL) {
+ ret->iso_copyright_file_id = strdup ("");
+ if (ret->iso_copyright_file_id == NULL) goto error;
+ }
+ if (ret->iso_abstract_file_id == NULL) {
+ ret->iso_abstract_file_id = strdup ("");
+ if (ret->iso_abstract_file_id == NULL) goto error;
+ }
+ if (ret->iso_bibliographic_file_id == NULL) {
+ ret->iso_bibliographic_file_id = strdup ("");
+ if (ret->iso_bibliographic_file_id == NULL) goto error;
+ }
+
+ return ret;
+
+ error:
+ free (ret->iso_system_id);
+ free (ret->iso_volume_id);
+ free (ret->iso_volume_set_id);
+ free (ret->iso_publisher_id);
+ free (ret->iso_data_preparer_id);
+ free (ret->iso_application_id);
+ free (ret->iso_copyright_file_id);
+ free (ret->iso_abstract_file_id);
+ free (ret->iso_bibliographic_file_id);
+ free (ret);
+ return NULL;
+}
+
+static guestfs_int_isoinfo *
+isoinfo (const char *path)
+{
+ char *out = NULL, *err = NULL;
+ int r;
+ char **lines = NULL;
+ guestfs_int_isoinfo *ret = NULL;
+
+ /* --debug is necessary to get additional fields, in particular
+ * the date & time fields.
+ */
+ r = command (&out, &err, "isoinfo", "--debug", "-d", "-i", path, NULL);
+ if (r == -1) {
+ reply_with_error ("%s", err);
+ goto done;
+ }
+
+ lines = split_lines (out);
+ if (lines == NULL)
+ goto done;
+
+ ret = parse_isoinfo (lines);
+ if (ret == NULL)
+ goto done;
+
+ done:
+ free (out);
+ free (err);
+ if (lines)
+ free_strings (lines);
+
+ return ret;
+}
+
+guestfs_int_isoinfo *
+do_isoinfo_device (const char *device)
+{
+ return isoinfo (device);
+}
+
+guestfs_int_isoinfo *
+do_isoinfo (const char *path)
+{
+ char *buf;
+ guestfs_int_isoinfo *ret;
+
+ buf = sysroot_path (path);
+ if (!buf) {
+ reply_with_perror ("malloc");
+ return NULL;
+ }
+
+ ret = isoinfo (buf);
+ free (buf);
+
+ return ret;
+}
diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml
index 454f5758..a2710080 100644
--- a/generator/generator_actions.ml
+++ b/generator/generator_actions.ml
@@ -6780,6 +6780,38 @@ using approximately C<percent> % of the free space remaining
in the volume group. Most usefully, when C<percent> is C<100>
this will create the largest possible LV.");
+ ("isoinfo_device", (RStruct ("isodata", "isoinfo"), [Device "device"], []), 313, [],
+ [InitNone, Always, TestOutputStruct (
+ [["isoinfo_device"; "/dev/sdd"]],
+ [CompareWithString ("iso_system_id", "LINUX");
+ CompareWithString ("iso_volume_id", "CDROM");
+ CompareWithString ("iso_volume_set_id", "");
+ CompareWithInt ("iso_volume_set_size", 1);
+ CompareWithInt ("iso_volume_sequence_number", 1);
+ CompareWithInt ("iso_logical_block_size", 2048)])],
+ "get ISO information from primary volume descriptor of device",
+ "\
+C<device> is an ISO device. This returns a struct of information
+read from the primary volume descriptor (the ISO equivalent of the
+superblock) of the device.
+
+Usually it is more efficient to use the L<isoinfo(1)> command
+with the I<-d> option on the host to analyze ISO files,
+instead of going through libguestfs.
+
+For information on the primary volume descriptor fields, see
+L<http://wiki.osdev.org/ISO_9660#The_Primary_Volume_Descriptor>");
+
+ ("isoinfo", (RStruct ("isodata", "isoinfo"), [Pathname "isofile"], []), 314, [],
+ [],
+ "get ISO information from primary volume descriptor of ISO file",
+ "\
+This is the same as C<guestfs_isoinfo_device> except that it
+works for an ISO file located inside some other mounted filesystem.
+Note that in the common case where you have added an ISO file
+as a libguestfs device, you would I<not> call this. Instead
+you would call C<guestfs_isoinfo_device>.");
+
]
let all_functions = non_daemon_functions @ daemon_functions
diff --git a/generator/generator_structs.ml b/generator/generator_structs.ml
index e44eca25..b894acec 100644
--- a/generator/generator_structs.ml
+++ b/generator/generator_structs.ml
@@ -191,6 +191,27 @@ let structs = [
"app_summary", FString;
"app_description", FString;
];
+
+ (* ISO primary volume descriptor. *)
+ "isoinfo", [
+ "iso_system_id", FString;
+ "iso_volume_id", FString;
+ "iso_volume_space_size", FUInt32;
+ "iso_volume_set_size", FUInt32;
+ "iso_volume_sequence_number", FUInt32;
+ "iso_logical_block_size", FUInt32;
+ "iso_volume_set_id", FString;
+ "iso_publisher_id", FString;
+ "iso_data_preparer_id", FString;
+ "iso_application_id", FString;
+ "iso_copyright_file_id", FString;
+ "iso_abstract_file_id", FString;
+ "iso_bibliographic_file_id", FString;
+ "iso_volume_creation_t", FInt64;
+ "iso_volume_modification_t", FInt64;
+ "iso_volume_expiration_t", FInt64;
+ "iso_volume_effective_t", FInt64;
+ ];
] (* end of structs *)
(* For bindings which want camel case *)
@@ -207,6 +228,7 @@ let camel_structs = [
"inotify_event", "INotifyEvent";
"partition", "Partition";
"application", "Application";
+ "isoinfo", "ISOInfo";
]
let camel_name_of_struct typ =
diff --git a/java/Makefile.inc b/java/Makefile.inc
index fddd9377..1a8d3cd8 100644
--- a/java/Makefile.inc
+++ b/java/Makefile.inc
@@ -32,4 +32,5 @@ java_built_sources = \
com/redhat/et/libguestfs/INotifyEvent.java \
com/redhat/et/libguestfs/Partition.java \
com/redhat/et/libguestfs/Application.java \
+ com/redhat/et/libguestfs/ISOInfo.java \
com/redhat/et/libguestfs/GuestFS.java
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 22e39b14..620d68fb 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -44,6 +44,7 @@ daemon/initrd.c
daemon/inotify.c
daemon/internal.c
daemon/is.c
+daemon/isoinfo.c
daemon/labels.c
daemon/link.c
daemon/ls.c
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index a1e0432c..9346fabb 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-312
+314