- for (i = 0; mountpoints[i] != NULL; i += 2) {
- if (STREQ (mountpoints[i+1], "/")) {
- if (STRNEQ (mountpoints[i], device)) {
- fprintf (stderr, _("%s: to access '%c:', mount %s on / first. One way to do this is:\n umount-all\n mount %s /\n"),
- program_name, drive_letter, device, device);
- free_strings (roots);
- free_strings (drives);
- free_strings (mountpoints);
- return NULL;
- }
- }
+static char *
+win_prefix_drive_letter (char drive_letter, const char *path)
+{
+ char **roots = NULL;
+ char **drives = NULL;
+ char **mountpoints = NULL;
+ char *device, *mountpoint, *ret = NULL;
+ size_t i;
+
+ /* Resolve the drive letter using the drive mappings table. */
+ roots = guestfs_inspect_get_roots (g);
+ if (roots == NULL)
+ goto out;
+ if (roots[0] == NULL) {
+ fprintf (stderr, _("%s: to use Windows drive letters, you must inspect the guest (\"-i\" option or run \"inspect-os\" command)\n"),
+ program_name);
+ goto out;
+ }
+ drives = guestfs_inspect_get_drive_mappings (g, roots[0]);
+ if (drives == NULL || drives[0] == NULL) {
+ fprintf (stderr, _("%s: to use Windows drive letters, this must be a Windows guest\n"),
+ program_name);
+ goto out;
+ }
+
+ device = NULL;
+ for (i = 0; drives[i] != NULL; i += 2) {
+ if (c_tolower (drives[i][0]) == drive_letter && drives[i][1] == '\0') {
+ device = drives[i+1];
+ break;