summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2011-10-21 12:28:45 +0100
committerRichard W.M. Jones <rjones@redhat.com>2011-10-21 12:29:12 +0100
commitf5172902bc9d92451c83dc3c1a85b5aeb975b43a (patch)
treea17b4ae760d7e69002b49219fdde899b1488cb3c /src
parent9a6e5369b2134a3bd2a6decda48bbf5ac9d7cd41 (diff)
downloadlibguestfs-f5172902bc9d92451c83dc3c1a85b5aeb975b43a.tar.gz
libguestfs-f5172902bc9d92451c83dc3c1a85b5aeb975b43a.tar.xz
libguestfs-f5172902bc9d92451c83dc3c1a85b5aeb975b43a.zip
Allow compilation without hivex (RHBZ#723474).
Diffstat (limited to 'src')
-rw-r--r--src/guestfs-internal.h5
-rw-r--r--src/inspect.c184
-rw-r--r--src/inspect_fs_windows.c4
3 files changed, 97 insertions, 96 deletions
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index 9b690b4a..d9e1264d 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -403,11 +403,12 @@ extern void guestfs___call_callbacks_message (guestfs_h *g, uint64_t event, cons
extern void guestfs___call_callbacks_array (guestfs_h *g, uint64_t event, const uint64_t *array, size_t array_len);
extern int guestfs___is_file_nocase (guestfs_h *g, const char *);
extern int guestfs___is_dir_nocase (guestfs_h *g, const char *);
-#if defined(HAVE_HIVEX)
-extern int guestfs___check_for_filesystem_on (guestfs_h *g, const char *device, int is_block, int is_partnum);
extern char *guestfs___download_to_tmp (guestfs_h *g, struct inspect_fs *fs, const char *filename, const char *basename, int64_t max_size);
extern char *guestfs___case_sensitive_path_silently (guestfs_h *g, const char *);
extern struct inspect_fs *guestfs___search_for_root (guestfs_h *g, const char *root);
+
+#if defined(HAVE_HIVEX)
+extern int guestfs___check_for_filesystem_on (guestfs_h *g, const char *device, int is_block, int is_partnum);
extern int guestfs___parse_unsigned_int (guestfs_h *g, const char *str);
extern int guestfs___parse_unsigned_int_ignore_trailing (guestfs_h *g, const char *str);
extern int guestfs___parse_major_minor (guestfs_h *g, struct inspect_fs *fs);
diff --git a/src/inspect.c b/src/inspect.c
index 67eb65f5..e83e8241 100644
--- a/src/inspect.c
+++ b/src/inspect.c
@@ -514,98 +514,6 @@ guestfs__inspect_get_hostname (guestfs_h *g, const char *root)
return safe_strdup (g, fs->hostname ? : "unknown");
}
-/* Download a guest file to a local temporary file. The file is
- * cached in the temporary directory, and is not downloaded again.
- *
- * The name of the temporary (downloaded) file is returned. The
- * caller must free the pointer, but does *not* need to delete the
- * temporary file. It will be deleted when the handle is closed.
- *
- * Refuse to download the guest file if it is larger than max_size.
- * On this and other errors, NULL is returned.
- *
- * There is actually one cache per 'struct inspect_fs *' in order
- * to handle the case of multiple roots.
- */
-char *
-guestfs___download_to_tmp (guestfs_h *g, struct inspect_fs *fs,
- const char *filename,
- const char *basename, int64_t max_size)
-{
- char *r;
- int fd;
- char devfd[32];
- int64_t size;
-
- /* Make the basename unique by prefixing it with the fs number. */
- if (asprintf (&r, "%s/%ld-%s", g->tmpdir, fs - g->fses, basename) == -1) {
- perrorf (g, "asprintf");
- return NULL;
- }
-
- /* If the file has already been downloaded, return. */
- if (access (r, R_OK) == 0)
- return r;
-
- /* Check size of remote file. */
- size = guestfs_filesize (g, filename);
- if (size == -1)
- /* guestfs_filesize failed and has already set error in handle */
- goto error;
- if (size > max_size) {
- error (g, _("size of %s is unreasonably large (%" PRIi64 " bytes)"),
- filename, size);
- goto error;
- }
-
- fd = open (r, O_WRONLY|O_CREAT|O_TRUNC|O_NOCTTY, 0600);
- if (fd == -1) {
- perrorf (g, "open: %s", r);
- goto error;
- }
-
- snprintf (devfd, sizeof devfd, "/dev/fd/%d", fd);
-
- if (guestfs_download (g, filename, devfd) == -1) {
- unlink (r);
- close (fd);
- goto error;
- }
-
- if (close (fd) == -1) {
- perrorf (g, "close: %s", r);
- unlink (r);
- goto error;
- }
-
- return r;
-
- error:
- free (r);
- return NULL;
-}
-
-struct inspect_fs *
-guestfs___search_for_root (guestfs_h *g, const char *root)
-{
- if (g->nr_fses == 0) {
- error (g, _("no inspection data: call guestfs_inspect_os first"));
- return NULL;
- }
-
- size_t i;
- struct inspect_fs *fs;
- for (i = 0; i < g->nr_fses; ++i) {
- fs = &g->fses[i];
- if (fs->is_root && STREQ (root, fs->device))
- return fs;
- }
-
- error (g, _("%s: root device not found: only call this function with a root device previously returned by guestfs_inspect_os"),
- root);
- return NULL;
-}
-
#else /* no hivex at compile time */
/* XXX These functions should be in an optgroup. */
@@ -786,3 +694,95 @@ guestfs___feature_available (guestfs_h *g, const char *feature)
return r == 0 ? 1 : 0;
}
+
+/* Download a guest file to a local temporary file. The file is
+ * cached in the temporary directory, and is not downloaded again.
+ *
+ * The name of the temporary (downloaded) file is returned. The
+ * caller must free the pointer, but does *not* need to delete the
+ * temporary file. It will be deleted when the handle is closed.
+ *
+ * Refuse to download the guest file if it is larger than max_size.
+ * On this and other errors, NULL is returned.
+ *
+ * There is actually one cache per 'struct inspect_fs *' in order
+ * to handle the case of multiple roots.
+ */
+char *
+guestfs___download_to_tmp (guestfs_h *g, struct inspect_fs *fs,
+ const char *filename,
+ const char *basename, int64_t max_size)
+{
+ char *r;
+ int fd;
+ char devfd[32];
+ int64_t size;
+
+ /* Make the basename unique by prefixing it with the fs number. */
+ if (asprintf (&r, "%s/%ld-%s", g->tmpdir, fs - g->fses, basename) == -1) {
+ perrorf (g, "asprintf");
+ return NULL;
+ }
+
+ /* If the file has already been downloaded, return. */
+ if (access (r, R_OK) == 0)
+ return r;
+
+ /* Check size of remote file. */
+ size = guestfs_filesize (g, filename);
+ if (size == -1)
+ /* guestfs_filesize failed and has already set error in handle */
+ goto error;
+ if (size > max_size) {
+ error (g, _("size of %s is unreasonably large (%" PRIi64 " bytes)"),
+ filename, size);
+ goto error;
+ }
+
+ fd = open (r, O_WRONLY|O_CREAT|O_TRUNC|O_NOCTTY, 0600);
+ if (fd == -1) {
+ perrorf (g, "open: %s", r);
+ goto error;
+ }
+
+ snprintf (devfd, sizeof devfd, "/dev/fd/%d", fd);
+
+ if (guestfs_download (g, filename, devfd) == -1) {
+ unlink (r);
+ close (fd);
+ goto error;
+ }
+
+ if (close (fd) == -1) {
+ perrorf (g, "close: %s", r);
+ unlink (r);
+ goto error;
+ }
+
+ return r;
+
+ error:
+ free (r);
+ return NULL;
+}
+
+struct inspect_fs *
+guestfs___search_for_root (guestfs_h *g, const char *root)
+{
+ if (g->nr_fses == 0) {
+ error (g, _("no inspection data: call guestfs_inspect_os first"));
+ return NULL;
+ }
+
+ size_t i;
+ struct inspect_fs *fs;
+ for (i = 0; i < g->nr_fses; ++i) {
+ fs = &g->fses[i];
+ if (fs->is_root && STREQ (root, fs->device))
+ return fs;
+ }
+
+ error (g, _("%s: root device not found: only call this function with a root device previously returned by guestfs_inspect_os"),
+ root);
+ return NULL;
+}
diff --git a/src/inspect_fs_windows.c b/src/inspect_fs_windows.c
index 7d09fd18..270b7616 100644
--- a/src/inspect_fs_windows.c
+++ b/src/inspect_fs_windows.c
@@ -571,6 +571,8 @@ map_registry_disk_blob (guestfs_h *g, const char *blob)
return ret;
}
+#endif /* defined(HAVE_HIVEX) */
+
char *
guestfs___case_sensitive_path_silently (guestfs_h *g, const char *path)
{
@@ -580,5 +582,3 @@ guestfs___case_sensitive_path_silently (guestfs_h *g, const char *path)
g->error_cb = old_error_cb;
return ret;
}
-
-#endif /* defined(HAVE_HIVEX) */