mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
fish, edit: specifies whether mount Windows as readonly
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user