From 4128e9da58f7b557a146d31d9e955546ebb048f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Pierre=20Andr=C3=A9?= Date: Fri, 11 Aug 2017 09:56:44 +0200 Subject: [PATCH] Logged falling back to mounting read-only When the ntfs image is unclean, usually because it was not unmounted properly from Windows, mounting read-write is denied and falls back to read-only. Log this situation in the syslog, so that users mounting through /etc/fstab can more easily know what is going on. Also remove the "rw" option if it was stated. --- src/lowntfs-3g.c | 6 +++++- src/ntfs-3g.c | 6 +++++- src/ntfs-3g_common.c | 5 +++++ src/ntfs-3g_common.h | 2 ++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/lowntfs-3g.c b/src/lowntfs-3g.c index 4bd211f6..87207ed8 100644 --- a/src/lowntfs-3g.c +++ b/src/lowntfs-3g.c @@ -4449,10 +4449,14 @@ int main(int argc, char *argv[]) /* Force read-only mount if the device was found read-only */ if (!ctx->ro && NVolReadOnly(ctx->vol)) { + ctx->rw = FALSE; ctx->ro = TRUE; if (ntfs_strinsert(&parsed_options, ",ro")) goto err_out; - } + ntfs_log_info("Could not mount read-write, trying read-only\n"); + } else + if (ctx->rw && ntfs_strinsert(&parsed_options, ",rw")) + goto err_out; /* We must do this after ntfs_open() to be able to set the blksize */ if (ctx->blkdev && set_fuseblk_options(&parsed_options)) goto err_out; diff --git a/src/ntfs-3g.c b/src/ntfs-3g.c index 9558d50b..b224e188 100644 --- a/src/ntfs-3g.c +++ b/src/ntfs-3g.c @@ -4212,10 +4212,14 @@ int main(int argc, char *argv[]) /* Force read-only mount if the device was found read-only */ if (!ctx->ro && NVolReadOnly(ctx->vol)) { + ctx->rw = FALSE; ctx->ro = TRUE; if (ntfs_strinsert(&parsed_options, ",ro")) goto err_out; - } + ntfs_log_info("Could not mount read-write, trying read-only\n"); + } else + if (ctx->rw && ntfs_strinsert(&parsed_options, ",rw")) + goto err_out; /* We must do this after ntfs_open() to be able to set the blksize */ if (ctx->blkdev && set_fuseblk_options(&parsed_options)) goto err_out; diff --git a/src/ntfs-3g_common.c b/src/ntfs-3g_common.c index 708b177e..8fd7ee11 100644 --- a/src/ntfs-3g_common.c +++ b/src/ntfs-3g_common.c @@ -85,6 +85,7 @@ const struct DEFOPTION optionlist[] = { { "atime", OPT_ATIME, FLGOPT_BOGUS }, { "relatime", OPT_RELATIME, FLGOPT_BOGUS }, { "delay_mtime", OPT_DMTIME, FLGOPT_DECIMAL | FLGOPT_OPTIONAL }, + { "rw", OPT_RW, FLGOPT_BOGUS }, { "fake_rw", OPT_FAKE_RW, FLGOPT_BOGUS }, { "fsname", OPT_FSNAME, FLGOPT_NOSUPPORT }, { "no_def_opts", OPT_NO_DEF_OPTS, FLGOPT_BOGUS }, @@ -291,6 +292,9 @@ char *parse_mount_options(ntfs_fuse_context_t *ctx, case OPT_FAKE_RW : ctx->ro = TRUE; break; + case OPT_RW : + ctx->rw = TRUE; + break; case OPT_NOATIME : ctx->atime = ATIME_DISABLED; break; @@ -542,6 +546,7 @@ char *parse_mount_options(ntfs_fuse_context_t *ctx, if (ctx->ro) { ctx->secure_flags &= ~(1 << SECURITY_ADDSECURIDS); ctx->hiberfile = FALSE; + ctx->rw = FALSE; } exit: free(options); diff --git a/src/ntfs-3g_common.h b/src/ntfs-3g_common.h index e2d8790d..bcffe4f7 100644 --- a/src/ntfs-3g_common.h +++ b/src/ntfs-3g_common.h @@ -51,6 +51,7 @@ enum { OPT_ATIME, OPT_RELATIME, OPT_DMTIME, + OPT_RW, OPT_FAKE_RW, OPT_FSNAME, OPT_NO_DEF_OPTS, @@ -135,6 +136,7 @@ typedef struct { ntfs_atime_t atime; s64 dmtime; BOOL ro; + BOOL rw; BOOL show_sys_files; BOOL hide_hid_files; BOOL hide_dot_files;