* information to the handle.
*/
/* Look to see if any devices directly contain filesystems (RHBZ#590167). */
- char **devices;
- devices = guestfs_list_devices (g);
+ char **devices = guestfs_list_devices (g);
if (devices == NULL)
return NULL;
guestfs___free_string_list (devices);
/* Look at all partitions. */
- char **partitions;
- partitions = guestfs_list_partitions (g);
+ char **partitions = guestfs_list_partitions (g);
if (partitions == NULL) {
guestfs___free_inspect_info (g);
return NULL;
}
guestfs___free_string_list (partitions);
+ /* Look at MD devices. */
+ char **mds = guestfs_list_md_devices (g);
+ if (mds == NULL) {
+ guestfs___free_inspect_info (g);
+ return NULL;
+ }
+
+ for (i = 0; mds[i] != NULL; ++i) {
+ if (guestfs___check_for_filesystem_on (g, mds[i], 0, i+1) == -1) {
+ guestfs___free_string_list (mds);
+ guestfs___free_inspect_info (g);
+ return NULL;
+ }
+ }
+ guestfs___free_string_list (mds);
+
/* Look at all LVs. */
if (guestfs___feature_available (g, "lvm2")) {
char **lvs;
return ret;
}
+static int
+compare_strings (const void *vp1, const void *vp2)
+{
+ const char *s1 = * (char * const *) vp1;
+ const char *s2 = * (char * const *) vp2;
+
+ return strcmp (s1, s2);
+}
+
char **
guestfs__inspect_get_roots (guestfs_h *g)
{
}
ret[count] = NULL;
+ qsort (ret, count, sizeof (char *), compare_strings);
+
return ret;
}
char *ret;
switch (fs->type) {
+ case OS_TYPE_FREEBSD: ret = safe_strdup (g, "freebsd"); break;
+ case OS_TYPE_HURD: ret = safe_strdup (g, "hurd"); break;
case OS_TYPE_LINUX: ret = safe_strdup (g, "linux"); break;
+ case OS_TYPE_NETBSD: ret = safe_strdup (g, "netbsd"); break;
case OS_TYPE_WINDOWS: ret = safe_strdup (g, "windows"); break;
- case OS_TYPE_FREEBSD: ret = safe_strdup (g, "freebsd"); break;
case OS_TYPE_UNKNOWN: default: ret = safe_strdup (g, "unknown"); break;
}
case OS_DISTRO_FEDORA: ret = safe_strdup (g, "fedora"); break;
case OS_DISTRO_GENTOO: ret = safe_strdup (g, "gentoo"); break;
case OS_DISTRO_LINUX_MINT: ret = safe_strdup (g, "linuxmint"); break;
+ case OS_DISTRO_MAGEIA: ret = safe_strdup (g, "mageia"); break;
case OS_DISTRO_MANDRIVA: ret = safe_strdup (g, "mandriva"); break;
case OS_DISTRO_MEEGO: ret = safe_strdup (g, "meego"); break;
+ case OS_DISTRO_OPENSUSE: ret = safe_strdup (g, "opensuse"); break;
case OS_DISTRO_PARDUS: ret = safe_strdup (g, "pardus"); break;
case OS_DISTRO_REDHAT_BASED: ret = safe_strdup (g, "redhat-based"); break;
case OS_DISTRO_RHEL: ret = safe_strdup (g, "rhel"); break;
case OS_DISTRO_SCIENTIFIC_LINUX: ret = safe_strdup (g, "scientificlinux"); break;
case OS_DISTRO_SLACKWARE: ret = safe_strdup (g, "slackware"); break;
+ case OS_DISTRO_TTYLINUX: ret = safe_strdup (g, "ttylinux"); break;
case OS_DISTRO_WINDOWS: ret = safe_strdup (g, "windows"); break;
case OS_DISTRO_UBUNTU: ret = safe_strdup (g, "ubuntu"); break;
case OS_DISTRO_UNKNOWN: default: ret = safe_strdup (g, "unknown"); break;
case OS_PACKAGE_FORMAT_PACMAN: ret = safe_strdup (g, "pacman"); break;
case OS_PACKAGE_FORMAT_EBUILD: ret = safe_strdup (g, "ebuild"); break;
case OS_PACKAGE_FORMAT_PISI: ret = safe_strdup (g, "pisi"); break;
+ case OS_PACKAGE_FORMAT_PKGSRC: ret = safe_strdup (g, "pkgsrc"); break;
case OS_PACKAGE_FORMAT_UNKNOWN:
default:
ret = safe_strdup (g, "unknown");
case OS_PACKAGE_MANAGEMENT_PORTAGE: ret = safe_strdup (g, "portage"); break;
case OS_PACKAGE_MANAGEMENT_PISI: ret = safe_strdup (g, "pisi"); break;
case OS_PACKAGE_MANAGEMENT_URPMI: ret = safe_strdup (g, "urpmi"); break;
+ case OS_PACKAGE_MANAGEMENT_ZYPPER: ret = safe_strdup (g, "zypper"); break;
case OS_PACKAGE_MANAGEMENT_UNKNOWN:
default:
ret = safe_strdup (g, "unknown");
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. */
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/%td-%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;
+}