[Libguestfs] [PATCH 02/13] fish, edit: specifies whether mount Windows as readonly

Pino Toscano ptoscano at redhat.com
Thu Aug 28 13:21:05 UTC 2014


---
 edit/edit.c    |  3 ++-
 fish/windows.c | 11 ++++++-----
 fish/windows.h |  4 +++-
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/edit/edit.c b/edit/edit.c
index d4ce747..cd91b5f 100644
--- a/edit/edit.c
+++ b/edit/edit.c
@@ -336,7 +336,8 @@ edit (const char *filename, const char *root)
 
   /* Windows?  Special handling is required. */
   if (root != NULL && is_windows (g, root))
-    filename = filename_to_free = windows_path (g, root, filename);
+    filename = filename_to_free = windows_path (g, root, filename,
+                                                0 /* not read only */);
 
   /* Download the file to a temporary. */
   fd = mkstemp (tmpfile);
diff --git a/fish/windows.c b/fish/windows.c
index ddf2af1..06dcab3 100644
--- a/fish/windows.c
+++ b/fish/windows.c
@@ -33,7 +33,7 @@
 #include "c-ctype.h"
 
 static void mount_drive_letter (guestfs_h *g, char drive_letter,
-                                const char *root);
+                                const char *root, int readonly);
 
 int
 is_windows (guestfs_h *g, const char *root)
@@ -48,7 +48,7 @@ is_windows (guestfs_h *g, const char *root)
 }
 
 char *
-windows_path (guestfs_h *g, const char *root, const char *path)
+windows_path (guestfs_h *g, const char *root, const char *path, int readonly)
 {
   char *ret;
   size_t i;
@@ -57,7 +57,7 @@ windows_path (guestfs_h *g, const char *root, const char *path)
   if (c_isalpha (path[0]) && path[1] == ':') {
     char drive_letter = c_tolower (path[0]);
     /* This returns the newly allocated string. */
-    mount_drive_letter (g, drive_letter, root);
+    mount_drive_letter (g, drive_letter, root, readonly);
     ret = strdup (path + 2);
     if (ret == NULL) {
       perror ("strdup");
@@ -94,7 +94,8 @@ windows_path (guestfs_h *g, const char *root, const char *path)
 }
 
 static void
-mount_drive_letter (guestfs_h *g, char drive_letter, const char *root)
+mount_drive_letter (guestfs_h *g, char drive_letter, const char *root,
+                    int readonly)
 {
   char *device;
   size_t i;
@@ -126,7 +127,7 @@ mount_drive_letter (guestfs_h *g, char drive_letter, const char *root)
   if (guestfs_umount_all (g) == -1)
     exit (EXIT_FAILURE);
 
-  if (guestfs_mount (g, device, "/") == -1)
+  if ((readonly ? guestfs_mount_ro : guestfs_mount) (g, device, "/") == -1)
     exit (EXIT_FAILURE);
 
   /* Don't need to free (device) because that string was in the
diff --git a/fish/windows.h b/fish/windows.h
index bb68634..5543182 100644
--- a/fish/windows.h
+++ b/fish/windows.h
@@ -36,9 +36,11 @@ extern int is_windows (guestfs_h *g, const char *root);
  *  - 'root' must be a Windows installation
  *  - relies on an already being done introspection
  *  - will unmount all the existing mount points and mount the Windows root
+ *    (according to 'readonly')
  *  - will exit() on memory allocation failures, and if it is not possible
  *    to get the true path on case-insensitive filesystems
  */
-extern char *windows_path (guestfs_h *g, const char *root, const char *path);
+extern char *windows_path (guestfs_h *g, const char *root, const char *path,
+                           int readonly);
 
 #endif
-- 
1.9.3




More information about the Libguestfs mailing list