From 2514ce6a4200a42a7d168a85132610c5c118df9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Pierre=20Andr=C3=A9?= Date: Wed, 22 Aug 2018 09:43:19 +0200 Subject: [PATCH] Attempted mounting read-only after failed permission to read-write If a partition image could not be opened read-write, retry as read-only --- libntfs-3g/unix_io.c | 3 +++ libntfs-3g/volume.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libntfs-3g/unix_io.c b/libntfs-3g/unix_io.c index c88e8f82..1103c7e3 100644 --- a/libntfs-3g/unix_io.c +++ b/libntfs-3g/unix_io.c @@ -143,6 +143,9 @@ static int ntfs_device_unix_io_open(struct ntfs_device *dev, int flags) *(int*)dev->d_private = open(dev->d_name, flags); if (*(int*)dev->d_private == -1) { err = errno; + /* if permission error and rw, retry read-only */ + if ((err == EACCES) && ((flags & O_RDWR) == O_RDWR)) + err = EROFS; goto err_out; } #ifdef HAVE_LINUX_FS_H diff --git a/libntfs-3g/volume.c b/libntfs-3g/volume.c index d36c7d55..7a1bcf29 100644 --- a/libntfs-3g/volume.c +++ b/libntfs-3g/volume.c @@ -529,7 +529,7 @@ ntfs_volume *ntfs_volume_startup(struct ntfs_device *dev, dev->d_name); goto error_exit; } else { - ntfs_log_info("Can only open '%s' as read-only\n", + ntfs_log_info("Error opening '%s' read-write\n", dev->d_name); NVolSetReadOnly(vol); }