X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=src%2Finspect.c;h=5bd332fbbf33e82e908343ac254458127a062f97;hp=1f4096d1529f8a39339d10094eb7dddaaa9bf16c;hb=06fef60db5c7a96cb59aa92c4708e10333345e90;hpb=c9c0ac7d362fd19214c2c5e5bb7dcd9059950887 diff --git a/src/inspect.c b/src/inspect.c index 1f4096d..5bd332f 100644 --- a/src/inspect.c +++ b/src/inspect.c @@ -31,6 +31,7 @@ #include #include +#include "c-ctype.h" #include "ignore-value.h" #include "xstrtol.h" @@ -455,6 +456,7 @@ guestfs___free_inspect_info (guestfs_h *g) free (g->fses[i].device); free (g->fses[i].product_name); free (g->fses[i].arch); + free (g->fses[i].windows_systemroot); size_t j; for (j = 0; j < g->fses[i].nr_fstab; ++j) { free (g->fses[i].fstab[j].device); @@ -501,10 +503,8 @@ static int check_filesystem (guestfs_h *g, const char *device); static int check_linux_root (guestfs_h *g, struct inspect_fs *fs); static int check_fstab (guestfs_h *g, struct inspect_fs *fs); static int check_windows_root (guestfs_h *g, struct inspect_fs *fs); -static int check_windows_arch (guestfs_h *g, struct inspect_fs *fs, - const char *systemroot); -static int check_windows_registry (guestfs_h *g, struct inspect_fs *fs, - const char *systemroot); +static int check_windows_arch (guestfs_h *g, struct inspect_fs *fs); +static int check_windows_registry (guestfs_h *g, struct inspect_fs *fs); static char *resolve_windows_path_silently (guestfs_h *g, const char *); static int extend_fses (guestfs_h *g); static int parse_unsigned_int (guestfs_h *g, const char *str); @@ -831,6 +831,12 @@ add_fstab_entry (guestfs_h *g, struct inspect_fs *fs, STREQ (mp, "/sys")) return 0; + /* Ignore /dev/fd (floppy disks) (RHBZ#642929) and CD-ROM drives. */ + if ((STRPREFIX (spec, "/dev/fd") && c_isdigit (spec[7])) || + STREQ (spec, "/dev/floppy") || + STREQ (spec, "/dev/cdrom")) + return 0; + /* Resolve UUID= and LABEL= to the actual device. */ char *device = NULL; if (STRPREFIX (spec, "UUID=")) @@ -878,39 +884,54 @@ add_fstab_entry (guestfs_h *g, struct inspect_fs *fs, } /* Resolve block device name to the libguestfs device name, eg. - * /dev/xvdb1 => /dev/vdb1. This assumes that disks were added in the - * same order as they appear to the real VM, which is a reasonable - * assumption to make. Return things like LV names unchanged (or - * anything we don't recognize). + * /dev/xvdb1 => /dev/vdb1; and /dev/mapper/VG-LV => /dev/VG/LV. This + * assumes that disks were added in the same order as they appear to + * the real VM, which is a reasonable assumption to make. Return + * anything we don't recognize unchanged. */ static char * resolve_fstab_device (guestfs_h *g, const char *spec) { - char **devices = guestfs_list_devices (g); - if (devices == NULL) - return NULL; + char *a1; + char *device = NULL; + + if (STRPREFIX (spec, "/dev/mapper/")) { + /* LVM2 does some strange munging on /dev/mapper paths for VGs and + * LVs which contain '-' character: + * + * > lvcreate LV--test VG--test 32 + * > debug ls /dev/mapper + * VG----test-LV----test + * + * This makes it impossible to reverse those paths directly, so + * we have implemented lvm_canonical_lv_name in the daemon. + */ + device = guestfs_lvm_canonical_lv_name (g, spec); + } + else if ((a1 = match1 (g, spec, re_xdev)) != NULL) { + char **devices = guestfs_list_devices (g); + if (devices == NULL) + return NULL; - size_t count; - for (count = 0; devices[count] != NULL; count++) - ; + size_t count; + for (count = 0; devices[count] != NULL; count++) + ; - char *device = NULL; - char *a1 = match1 (g, spec, re_xdev); - if (a1) { size_t i = a1[0] - 'a'; /* a1[0] is always [a-z] because of regex. */ if (i < count) { size_t len = strlen (devices[i]) + strlen (a1) + 16; device = safe_malloc (g, len); snprintf (device, len, "%s%s", devices[i], &a1[1]); } - } else { + + free (a1); + free_string_list (devices); + } + else { /* Didn't match device pattern, return original spec unchanged. */ device = safe_strdup (g, spec); } - free (a1); - free_string_list (devices); - return device; } @@ -940,34 +961,27 @@ check_windows_root (guestfs_h *g, struct inspect_fs *fs) return -1; } - /* XXX There is a case for exposing systemroot and many variables - * from the registry through the libguestfs API. - */ - if (g->verbose) fprintf (stderr, "windows %%SYSTEMROOT%% = %s", systemroot); - if (check_windows_arch (g, fs, systemroot) == -1) { - free (systemroot); + /* Freed by guestfs___free_inspect_info. */ + fs->windows_systemroot = systemroot; + + if (check_windows_arch (g, fs) == -1) return -1; - } - if (check_windows_registry (g, fs, systemroot) == -1) { - free (systemroot); + if (check_windows_registry (g, fs) == -1) return -1; - } - free (systemroot); return 0; } static int -check_windows_arch (guestfs_h *g, struct inspect_fs *fs, - const char *systemroot) +check_windows_arch (guestfs_h *g, struct inspect_fs *fs) { - size_t len = strlen (systemroot) + 32; + size_t len = strlen (fs->windows_systemroot) + 32; char cmd_exe[len]; - snprintf (cmd_exe, len, "%s/system32/cmd.exe", systemroot); + snprintf (cmd_exe, len, "%s/system32/cmd.exe", fs->windows_systemroot); char *cmd_exe_path = resolve_windows_path_silently (g, cmd_exe); if (!cmd_exe_path) @@ -987,8 +1001,7 @@ check_windows_arch (guestfs_h *g, struct inspect_fs *fs, * registry fields available to callers. */ static int -check_windows_registry (guestfs_h *g, struct inspect_fs *fs, - const char *systemroot) +check_windows_registry (guestfs_h *g, struct inspect_fs *fs) { TMP_TEMPLATE_ON_STACK (dir); #define dir_len (strlen (dir)) @@ -997,9 +1010,10 @@ check_windows_registry (guestfs_h *g, struct inspect_fs *fs, #define cmd_len (dir_len + 16) char cmd[cmd_len]; - size_t len = strlen (systemroot) + 64; + size_t len = strlen (fs->windows_systemroot) + 64; char software[len]; - snprintf (software, len, "%s/system32/config/software", systemroot); + snprintf (software, len, "%s/system32/config/software", + fs->windows_systemroot); char *software_path = resolve_windows_path_silently (g, software); if (!software_path) @@ -1253,6 +1267,21 @@ guestfs__inspect_get_product_name (guestfs_h *g, const char *root) return safe_strdup (g, fs->product_name ? : "unknown"); } +char * +guestfs__inspect_get_windows_systemroot (guestfs_h *g, const char *root) +{ + struct inspect_fs *fs = search_for_root (g, root); + if (!fs) + return NULL; + + if (!fs->windows_systemroot) { + error (g, _("not a Windows guest, or systemroot could not be determined")); + return NULL; + } + + return safe_strdup (g, fs->windows_systemroot); +} + char ** guestfs__inspect_get_mountpoints (guestfs_h *g, const char *root) {